示例#1
0
def tcp_link(sock, addr):
    print('Accept new connection from %s:%s...' % addr)
    request = sock.recv(1024)
    http_req = HttpRequest()
    http_req.passRequest(request)
    sock.send(http_req.getResponse())
    sock.close()
示例#2
0
def tcp_link(sock, addr):
    print('Accept new connection from %s:%s...' % addr)
    request = None
    Content_Length = 0
    try:
        bb = True
        tmprequest = sock.recv(10240)
        request = tmprequest
        pat = b"Content-Length: (.*?)\r"
        Content_Length = 0
        cont = re.findall(pat, request)
        tmplen = cont[0]
        tmpint = tmplen.decode()
        Content_Length = int(tmpint)
        while len(request) < Content_Length:
            tmprequest = sock.recv(10240)
            request = request + tmprequest
    except Exception as e:
        pass

    http_req = HttpRequest()
    http_req.passRequest(request)
    try:
        sock.send(http_req.getResponse().encode('utf-8'))
    except Exception as e:
        print(e)
    sock.close()