示例#1
0
 def response_handler(sock):
     consume_socket_content(sock, timeout=0.5)
     sock.send(
         b'HTTP/1.1 200 OK\r\n'
         b'Content-Length: 18\r\n\r\n'
         b'\xff\xfe{\x00"\x00K0"\x00=\x00"\x00\xab0"\x00\r\n'
     )
示例#2
0
 def digest_response_handler(sock):
     # Respond to GET with a 200 containing www-authenticate header.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert request_content.startswith(b"GET / HTTP/1.1")
     sock.send(text_200_chal)
     # Verify the client didn't respond with auth.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert request_content == b""
     return request_content
示例#3
0
 def redirect_resp_handler(sock):
     consume_socket_content(sock, timeout=0.5)
     location = u"//{}:{}/{}".format(host, port, path)
     sock.send(b"HTTP/1.1 301 Moved Permanently\r\n"
               b"Content-Length: 0\r\n"
               b"Location: " + location.encode("utf8") + b"\r\n"
               b"\r\n")
     redirect_request.append(consume_socket_content(sock, timeout=0.5))
     sock.send(b"HTTP/1.1 200 OK\r\n\r\n")
示例#4
0
 def redirect_resp_handler(sock):
     consume_socket_content(sock, timeout=0.5)
     location = u'//{}:{}/{}'.format(host, port, path)
     sock.send(b'HTTP/1.1 301 Moved Permanently\r\n'
               b'Content-Length: 0\r\n'
               b'Location: ' + location.encode('utf8') + b'\r\n'
               b'\r\n')
     redirect_request.append(consume_socket_content(sock, timeout=0.5))
     sock.send(b'HTTP/1.1 200 OK\r\n\r\n')
示例#5
0
    def digest_response_handler(sock):
        # Respond to GET with a 200 containing www-authenticate header.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert request_content.startswith(b"GET / HTTP/1.1")
        sock.send(text_200_chal)

        # Verify the client didn't respond with auth.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert request_content == b''

        return request_content
示例#6
0
 def redirect_resp_handler(sock):
     consume_socket_content(sock, timeout=0.5)
     location = u'//{0}:{1}/{2}'.format(host, port, path)
     sock.send(
         b'HTTP/1.1 301 Moved Permanently\r\n'
         b'Content-Length: 0\r\n'
         b'Location: ' + location.encode('utf8') + b'\r\n'
         b'\r\n'
     )
     redirect_request.append(consume_socket_content(sock, timeout=0.5))
     sock.send(b'HTTP/1.1 200 OK\r\n\r\n')
示例#7
0
 def redirect_resp_handler(sock):
     consume_socket_content(sock, timeout=0.5)
     location = f'//{host}:{port}/{path}'
     sock.send(
         (
             b'HTTP/1.1 301 Moved Permanently\r\n'
             b'Content-Length: 0\r\n'
             b'Location: %s\r\n'
             b'\r\n'
         ) % location.encode('utf8')
     )
     redirect_request.append(consume_socket_content(sock, timeout=0.5))
     sock.send(b'HTTP/1.1 200 OK\r\n\r\n')
示例#8
0
 def digest_failed_response_handler(sock):
     # Respond to initial GET with a challenge.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert request_content.startswith(b"GET / HTTP/1.1")
     sock.send(text_401)
     # Verify we receive an Authorization header in response, then
     # challenge again.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert expected_digest in request_content
     sock.send(text_401)
     # Verify the client didn't respond to second challenge.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert request_content == b""
     return request_content
示例#9
0
 def response_handler(sock):
     req = consume_socket_content(sock, timeout=0.5)
     sock.send(
         b'HTTP/1.1 200 OK\r\n'
         b'Content-Length: '+bytes(len(req))+b'\r\n'
         b'\r\n'+req
     )
示例#10
0
    def incomplete_chunked_response_handler(sock):
        request_content = consume_socket_content(sock, timeout=0.5)

        # The server never ends the request and doesn't provide any valid chunks
        sock.send(b"HTTP/1.1 200 OK\r\n" + b"Transfer-Encoding: chunked\r\n")

        return request_content
示例#11
0
 def response_handler(sock):
     req = consume_socket_content(sock, timeout=0.5)
     sock.send(
         b'HTTP/1.1 200 OK\r\n'
         b'Content-Length: '+bytes(len(req))+b'\r\n'
         b'\r\n'+req
     )
示例#12
0
    def multiple_content_length_response_handler(sock):
        request_content = consume_socket_content(sock, timeout=0.5)

        sock.send(b"HTTP/1.1 200 OK\r\n" + b"Content-Type: text/plain\r\n" +
                  b"Content-Length: 16\r\n" + b"Content-Length: 32\r\n\r\n" +
                  b"-- Bad Actor -- Original Content\r\n")

        return request_content
示例#13
0
def echo_response_handler(sock):
    """Simple handler that will take request and echo it back to requester."""
    request_content = consume_socket_content(sock, timeout=0.5)

    text_200 = (b'HTTP/1.1 200 OK\r\n'
                b'Content-Length: %d\r\n\r\n'
                b'%s') % (len(request_content), request_content)
    sock.send(text_200)
示例#14
0
    def digest_failed_response_handler(sock):
        # Respond to initial GET with a challenge.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert request_content.startswith(b"GET / HTTP/1.1")
        sock.send(text_401)

        # Verify we receive an Authorization header in response, then
        # challenge again.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert expected_digest in request_content
        sock.send(text_401)

        # Verify the client didn't respond to second challenge.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert request_content == b''

        return request_content
示例#15
0
    def response_handler(sock):
        _req = consume_socket_content(sock, timeout=0.5)

        # Send invalid chunked data (length mismatch)
        sock.send(b'HTTP/1.1 200 OK\r\n'
                  b'Transfer-Encoding: chunked\r\n'
                  b'\r\n2\r\n42\r\n8\r\n123\r\n'  # 5 bytes missing
                  )
示例#16
0
 def digest_response_handler(sock):
     # Respond to initial GET with a challenge.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert request_content.startswith(b"GET / HTTP/1.1")
     sock.send(text_401)
     # Verify we receive an Authorization header in response, then redirect.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert expected_digest in request_content
     sock.send(text_302)
     # Verify Authorization isn't sent to the redirected host,
     # then send another challenge.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert b"Authorization:" not in request_content
     sock.send(text_401)
     # Verify Authorization is sent correctly again, and return 200 OK.
     request_content = consume_socket_content(sock, timeout=0.5)
     assert expected_digest in request_content
     sock.send(text_200)
     return request_content
示例#17
0
    def digest_response_handler(sock):
        # Respond to initial GET with a challenge.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert request_content.startswith(b"GET / HTTP/1.1")
        sock.send(text_401)

        # Verify we receive an Authorization header in response, then redirect.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert expected_digest in request_content
        sock.send(text_302)

        # Verify Authorization isn't sent to the redirected host,
        # then send another challenge.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert b'Authorization:' not in request_content
        sock.send(text_401)

        # Verify Authorization is sent correctly again, and return 200 OK.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert expected_digest in request_content
        sock.send(text_200)

        return request_content
示例#18
0
 def response_handler(sock):
     consume_socket_content(sock, timeout=0.5)
     sock.send(b'HTTP/1.1 302 FOUND\r\n'
               b'Content-Length: 0\r\n'
               b'Location: /get#relevant-section\r\n\r\n')
     consume_socket_content(sock, timeout=0.5)
     sock.send(b'HTTP/1.1 302 FOUND\r\n'
               b'Content-Length: 0\r\n'
               b'Location: /final-url/\r\n\r\n')
     consume_socket_content(sock, timeout=0.5)
     sock.send(b'HTTP/1.1 200 OK\r\n\r\n')
示例#19
0
 def response_handler(sock):
     consume_socket_content(sock, timeout=0.5)
     sock.send(
         b'HTTP/1.1 302 FOUND\r\n'
         b'Content-Length: 0\r\n'
         b'Location: /get#relevant-section\r\n\r\n'
     )
     consume_socket_content(sock, timeout=0.5)
     sock.send(
         b'HTTP/1.1 302 FOUND\r\n'
         b'Content-Length: 0\r\n'
         b'Location: /final-url/\r\n\r\n'
     )
     consume_socket_content(sock, timeout=0.5)
     sock.send(
         b'HTTP/1.1 200 OK\r\n\r\n'
     )