Skip to content

Instantly share code, notes, and snippets.

@endofline endofline/rsws-banned.py
Last active Jul 24, 2017

Embed
What would you like to do?
really simple web server (rsws) serving singlepage.html
#!/usr/bin/python
import logging
logging.basicConfig(filename='rsws.log',level=logging.DEBUG)
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
def _send_single_page(self):
with open('singlepage.html', 'r') as myfile:
content = myfile.read()
self.wfile.write(content)
def do_GET(self):
self._set_headers()
self._send_single_page()
def do_HEAD(self):
self._set_headers()
def do_POST(self):
# Doesn't do anything with posted data
self._set_headers()
self._send_single_page()
def log_message(self, format, *args):
logging.info("{1} {0} {2}".format(self.address_string(), self.log_date_time_string(), format%args))
def run(server_class=HTTPServer, handler_class=S, port=90):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
logging.info("starting httpd on port {}".format(port))
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
run()
<h1>rsws works!</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.