def _dump_request_data_only(request, prefixes, bytearr, proxy_info=None, n=0):

    if proxy_info is None:
        proxy_info = {}

    prefix = prefixes.request
    method = _coerce_to_bytes(proxy_info.pop('method', request.method))
    request_path, uri = _build_request_path(request.url, proxy_info)

    # <prefix><METHOD> <request-path> HTTP/1.1
    bytearr.extend(prefix + method + b'' + request_path + b' HTTP/1.1\r\n')

    # <prefix>Host: <request-host> OR host header specified by user
    headers = request.headers.copy()
    host_header = _coerce_to_bytes(headers.pop('Host', uri.netloc))
    bytearr.extend(prefix + b'Host: ' + host_header + b'\r\n')

    for name, value in headers.items():
        bytearr.extend(prefix + _format_header(name, value))

    bytearr.extend(prefix + b'\r\n')
    if request.body:
        if isinstance(request.body, compat.basestring):
            bytearr.extend(prefix + _coerce_to_bytes(request.body))
        else:
            bytearr.extend(b'<< Request body is not a string-like type >>')
    bytearr.extend(b'\r\n')
    t = str(int(time.time()))
    print(type(t), t)
    txt = bytearr.decode("utf-8")
    print(type(txt))
    with open(str(n) + "_c.txt", "wb") as f:
        f.write(bytearr)
 def test_build_request_path_with_proxy_info(self):
     """Show that we defer to the proxy request_path info."""
     path, _ = dump._build_request_path(
         'https://example.com/', {
             'request_path': b'https://example.com/test'
         }
     )
     assert path == b'https://example.com/test'
 def test_build_request_path_with_query_string(self):
     """Show we include query strings appropriately."""
     path, _ = dump._build_request_path(
         'https://example.com/foo/bar?query=data', {}
     )
     assert path == b'/foo/bar?query=data'
 def test_build_request_path(self):
     """Show we get the right request path for a normal request."""
     path, _ = dump._build_request_path(
         'https://example.com/foo/bar', {}
     )
     assert path == b'/foo/bar'
Beispiel #5
0
 def test_build_request_path_with_proxy_info(self):
     """Show that we defer to the proxy request_path info."""
     path, _ = dump._build_request_path(
         'https://example.com/',
         {'request_path': b'https://example.com/test'})
     assert path == b'https://example.com/test'
Beispiel #6
0
 def test_build_request_path_with_query_string(self):
     """Show we include query strings appropriately."""
     path, _ = dump._build_request_path(
         'https://example.com/foo/bar?query=data', {})
     assert path == b'/foo/bar?query=data'
Beispiel #7
0
 def test_build_request_path(self):
     """Show we get the right request path for a normal request."""
     path, _ = dump._build_request_path('https://example.com/foo/bar', {})
     assert path == b'/foo/bar'