Last active
April 4, 2016 11:49
-
-
Save chuwy/5ef911ba1e459cbbfdcd8fa94942a81e to your computer and use it in GitHub Desktop.
Webserver printing headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Webserver printing headers | |
""" | |
import SimpleHTTPServer | |
import SocketServer | |
import logging | |
import sys | |
count = 0 | |
class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
def do_POST(self): | |
logging.error(self.headers) | |
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) | |
def do_GET(self): | |
global count | |
print(count) | |
count = count + 1 | |
if count > 5: | |
logging.error(self.headers) | |
self.send_response(200, None) | |
self.send_header('Content-type', 'text/plain') | |
self.send_header('Accept-Ranges', 'bytes') | |
self.send_header('Connection', 'close') | |
self.end_headers() | |
self.wfile.write(bytearray("bye", 'utf-8')) | |
else: | |
logging.error(self.headers) | |
self.send_response(404, None) | |
self.send_header('Content-type', 'text/plain') | |
self.send_header('Accept-Ranges', 'bytes') | |
self.send_header('Connection', 'close') | |
self.end_headers() | |
self.wfile.write(bytearray("fuck", 'utf-8')) | |
try: | |
port = int(sys.argv[1]) | |
except: | |
port = 8082 | |
Handler = GetHandler | |
httpd = SocketServer.TCPServer(("0.0.0.0", port), Handler) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment