MCPcopy
hub / github.com/scrapy/scrapy / request_httprepr

Function request_httprepr

scrapy/utils/request.py:126–140  ·  view source on GitHub ↗

Return the raw HTTP representation (as bytes) of the given request. This is provided only for reference since it's not the actual stream of bytes that will be send when performing the request (that's controlled by Twisted).

(request: Request)

Source from the content-addressed store, hash-verified

124
125
126def request_httprepr(request: Request) -> bytes:
127 """Return the raw HTTP representation (as bytes) of the given request.
128 This is provided only for reference since it's not the actual stream of
129 bytes that will be send when performing the request (that's controlled
130 by Twisted).
131 """
132 parsed = urlparse_cached(request)
133 path = urlunparse(("", "", parsed.path or "/", parsed.params, parsed.query, ""))
134 s = to_bytes(request.method) + b" " + to_bytes(path) + b" HTTP/1.1\r\n"
135 s += b"Host: " + to_bytes(parsed.hostname or b"") + b"\r\n"
136 if request.headers:
137 s += request.headers.to_string() + b"\r\n"
138 s += b"\r\n"
139 s += request.body
140 return s
141
142
143def referer_str(request: Request) -> str | None:

Callers 3

process_requestMethod · 0.90
test_request_httpreprFunction · 0.90

Calls 3

urlparse_cachedFunction · 0.90
to_bytesFunction · 0.90
to_stringMethod · 0.80

Tested by 2

test_request_httpreprFunction · 0.72