Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from http.server import BaseHTTPRequestHandler, HTTPServer
- class RequestHandler(BaseHTTPRequestHandler):
- def do_GET(self):
- # Get the current requested URL
- current_url = self.path
- # Set the response status code
- self.send_response(200)
- # Set the response headers
- self.send_header('Content-type', 'text/html')
- self.end_headers()
- # Create the HTML page with the current URL
- html = f"""
- <html>
- <head>
- <title>Current Requested URL</title>
- </head>
- <body>
- <h1>Current Requested URL:</h1>
- <p>{current_url}</p>
- </body>
- </html>
- """
- # Send the HTML response to the client
- self.wfile.write(html.encode('utf-8'))
- def run_server(port=7000):
- server_address = ('', port)
- httpd = HTTPServer(server_address, RequestHandler)
- print(f'Starting server on port {port}...')
- httpd.serve_forever()
- if __name__ == '__main__':
- run_server()
Advertisement
Comments
-
Comment was deleted
-
- This is a script used for demoing the nginx load balance technique explained in this learning nginx blog: https://sophiazhang.com/post/start-with-nginx/
Add Comment
Please, Sign In to add comment
Advertisement