Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request Headers (scheme)
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to store columns of a .csv in variables (when the .csv has no headers) ? hobbyist 6 1,426 Aug-18-2023, 02:06 PM
Last Post: deanhystad
  TreeView column headers TWB 2 2,570 Jan-29-2023, 02:13 PM
Last Post: TWB
  export sql table to csv using BCP with headers mg24 0 769 Jan-19-2023, 05:36 AM
Last Post: mg24
  Code changing rder of headers Led_Zeppelin 0 946 Jul-13-2022, 05:38 PM
Last Post: Led_Zeppelin
  how can I correct the Bad Request error on my curl request tomtom 8 5,242 Oct-03-2021, 06:32 AM
Last Post: tomtom
  Capture Scheme ( http e https ) JohnnyCoffee 0 2,020 Mar-27-2021, 03:10 PM
Last Post: JohnnyCoffee
  Reading csv with multiple "headers" Clives 3 2,604 Dec-31-2020, 09:25 AM
Last Post: Ana_junior
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 4,013 Jun-18-2020, 08:07 AM
Last Post: buran
  Spyder IDE - make variable explorer to follow the color scheme of the Editor Antonio 0 5,537 May-05-2018, 10:20 PM
Last Post: Antonio
  Color Scheme jliu0928 1 3,284 Aug-19-2017, 03:18 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020