Skip to content

Instantly share code, notes, and snippets.

@tomazas
Last active January 18, 2022 08:23
Show Gist options
  • Save tomazas/0282a95e8cdaafc11d721eda1a0522f6 to your computer and use it in GitHub Desktop.
Save tomazas/0282a95e8cdaafc11d721eda1a0522f6 to your computer and use it in GitHub Desktop.
# python 2 HTTP GET single-threaded server
# input: HTTP XML payload loded from payload.txt file
#
import SimpleHTTPServer
import SocketServer
hostName = "localhost"
serverPort = 8000
payload = ""
with file("payload.txt") as fp:
payload = fp.read()
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/xml')
self.end_headers()
self.wfile.write(payload)
print "starting %s:%d"%(hostName, serverPort)
httpd = SocketServer.TCPServer((hostName, serverPort), Handler)
httpd.serve_forever()
print "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment