Complete network lab transport and HTTP comparisons

This commit is contained in:
patayatuya-art committed 2026-12-01 01:16:02 +03:00
1 parent a33e028581
commit 79ca3743b9
8 files changed
+52 -11

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
"""Send the same HTTP headers as requests over a raw TCP connection."""
import socket
from http.client import HTTPResponse
from requests.utils import default_headers
def main() -> None:
host = "vyatsu.ru"
headers = {"Host": host, **default_headers(), "Connection": "close"}
lines = ["GET / HTTP/1.1", *(f"{name}: {value}" for name, value in headers.items())]
request = "\r\n".join([*lines, "", ""])
with socket.create_connection((host, 80), timeout=10) as client:
client.sendall(request.encode("ascii"))
response = HTTPResponse(client)
try:
response.begin()
print(f"HTTP/1.1 {response.status} {response.reason}")
print(response.headers, end="")
finally:
response.close()
if __name__ == "__main__":
main()