<commit_before>from aquests.protocols.http import request, response
from ..wastuff import triple_logger
from ..http_server import http_server
from ..handlers import pingpong_handler
from ..handlers.http2.response import response as http2_response
from ..http_response import http_response
from ..handlers import vhost_handler
import skitai
from skitai import lifetime
import asyncore

def get_default_handler ():
    for h in skitai.was.httpserver.handlers:
        if isinstance (h, vhost_handler.Handler):
            return h

def process_request (request, handler = None):
    # clinet request -> server request
    handler = handler or get_default_handler ()
    assert handler.match (request)
    handler.handle_request (request)
    if request.command in ('post', 'put', 'patch'):
        request.collector.collect_incoming_data (request.payload)
        request.collector.found_terminator ()        
    return request    
     
def get_response (request, handler = None):
    # clinet request -> server response
    request = process_request (request, handler)
    return request.response

def get_client_response (request, handler = None):
    # clinet request -> process -> server response -> client response
    # this will be used by client.Client    
    request = process_request (request, handler)
    while 1:
        result = request.channel.socket.getvalue ()
        if result:
            break
        
    try:
        header, payload = result.split (b"\r\n\r\n", 1)
    except ValueError:
        raise ValueError (str (result))
    resp = response.Response (request, header.decode ("utf8"))
    resp.collect_incoming_data (payload)
    return resp

#------------------------------------------------------------------
def Server (log = None):
    log = log or triple_logger.Logger ("screen", None) 
    s = http_server ('0.0.0.0', 3000, log.get ("server"), log.get ("request"))    
    s.install_handler (pingpong_handler.Handler ())
    return s

<commit_msg>fix post without data at testutil.server<commit_after>from aquests.protocols.http import request, response
from ..wastuff import triple_logger
from ..http_server import http_server
from ..handlers import pingpong_handler
from ..handlers.http2.response import response as http2_response
from ..http_response import http_response
from ..handlers import vhost_handler
import skitai
from skitai import lifetime
import asyncore

def get_default_handler ():
    for h in skitai.was.httpserver.handlers:
        if isinstance (h, vhost_handler.Handler):
            return h

def process_request (request, handler = None):
    # clinet request -> server request
    handler = handler or get_default_handler ()
    assert handler.match (request)
    handler.handle_request (request)
    if request.collector and request.command in ('post', 'put', 'patch'):
        request.collector.collect_incoming_data (request.payload)
        request.collector.found_terminator ()        
    return request    
     
def get_response (request, handler = None):
    # clinet request -> server response
    request = process_request (request, handler)
    return request.response

def get_client_response (request, handler = None):
    # clinet request -> process -> server response -> client response
    # this will be used by client.Client    
    request = process_request (request, handler)
    while 1:
        result = request.channel.socket.getvalue ()
        if result:
            break
        
    try:
        header, payload = result.split (b"\r\n\r\n", 1)
    except ValueError:
        raise ValueError (str (result))
    resp = response.Response (request, header.decode ("utf8"))
    resp.collect_incoming_data (payload)
    return resp

#------------------------------------------------------------------
def Server (log = None):
    log = log or triple_logger.Logger ("screen", None) 
    s = http_server ('0.0.0.0', 3000, log.get ("server"), log.get ("request"))    
    s.install_handler (pingpong_handler.Handler ())
    return s


{'fraction_non_alphanumeric': 0.12247946228528753, 'fraction_numerical': 0.006472491909385114, 'mean_word_length': 2.776315789473684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6855469', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1084, 'n_words': 341}