""" httpsrv.py Copyright 2019 (C) Mind Chasers Inc, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from http.server import HTTPServer, BaseHTTPRequestHandler import urllib HOST_ADDRESS = "" HOST_PORT = 8000 VERSION = "0.1a" class RequestHandler(BaseHTTPRequestHandler): """ Our custom, example request handler """ def send_response(self, code, message=None): """ override to customize header """ self.log_request(code) self.send_response_only(code) self.send_header('Server','python3 http.server Development Server') self.send_header('Date', self.date_time_string()) self.end_headers() def do_GET(self): """ response for a GET request """ self.send_response(200) self.wfile.write(b'') self.wfile.write(b'') self.wfile.write(b'
') self.wfile.write(b'Enter something:\ \ ') self.wfile.write(b'
') self.wfile.write(b'') def do_POST(self): """ response for a POST """ content_length = int(self.headers['Content-Length']) (input,value) = self.rfile.read(content_length).decode('utf-8').split('=') value = urllib.parse.unquote_plus(value) self.send_response(200) self.wfile.write(b'') self.wfile.write(b'') self.wfile.write(b'

You submitted ' + bytes(value,'utf-8') + b'

') self.wfile.write(b'') def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler): """ follows example shown on docs.python.org """ server_address = (HOST_ADDRESS, HOST_PORT) httpd = server_class(server_address, handler_class) httpd.serve_forever() if __name__ == '__main__': run(handler_class=RequestHandler)