Skip to content

Instantly share code, notes, and snippets.

@guillefix
Created August 25, 2020 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillefix/aadf40c41f60877924ef35fb3c630480 to your computer and use it in GitHub Desktop.
Save guillefix/aadf40c41f60877924ef35fb3c630480 to your computer and use it in GitHub Desktop.
bare python server
from http.server import BaseHTTPRequestHandler, HTTPServer
import re
import json
import numpy as np
class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
print(self.path)
self._set_headers()
query=self.path[1:]
response_string=""
self.wfile.write(bytes(str(response_string), "utf-8"))
def do_HEAD(self):
self._set_headers()
def do_POST(self):
# Doesn't do anything with posted data
self._set_headers()
self.wfile.write(bytes("<html><body><h1>POST!</h1></body></html>", "utf-8"))
def run(server_class=HTTPServer, handler_class=S, port=80):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print('Starting httpd...')
httpd.serve_forever()
run(port=42069)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment