Mar-31-2021, 09:17 PM
I'm doing tests to structure an http server, initially I use a socket to plug it in (client.side X server.side) this I do without problems, see the code below:
from http.server import BaseHTTPRequestHandler, HTTPServer, socketserver from http import HTTPStatus from urllib.parse import urlparse import sys class MyServer(BaseHTTPRequestHandler): # class attributes __version__ = "1.0" sys_version = "Python/" + sys.version.split()[0] server_version = "Servone/" + __version__ """ The request handler class for our server. It is instantiated once per connection to the server, and must override the handle() method to implement communication to the client. """ def do_HEAD(self): # instance attributes # c_scheme = urlparse(self.scheme) # v_path = c_path.path # print(c_scheme) self.send_response(HTTPStatus.OK.value, HTTPStatus.OK.phrase) self.send_header("Content-type","text/html; charset=utf-8") self.end_headers() def do_GET(self): self.do_HEAD() o_file = open("index.html", "r") s_file = o_file.read() self.request.sendall(s_file.encode("utf-8")) if __name__ == "__main__": HOST, PORT = "localhost", 8080 # Create the server, binding to localhost on port 8080 with socketserver.TCPServer((HOST, PORT), MyServer) as server: print("Activate the server; this will keep running until you") print("interrupt the program with Ctrl-C") server.serve_forever()The doubt I have is related to the request header because when I run the code above I notice that there are some components (scheme) of the request header (client.side) that do not appear in the developer tools in the network tab in headers in (browser). I did some tests accessing sites and the component (scheme) appears in the request headers as shown in the example below:
:scheme: http or https