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)
| 124 | |
| 125 | |
| 126 | def 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 | |
| 143 | def referer_str(request: Request) -> str | None: |