ClickHouse/dbms/tests/external_dictionaries/http_server.py

36 lines
934 B
Python
Raw Normal View History

#!/usr/bin/env python
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from os import curdir, sep
PORT_NUMBER = 58000
class myHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.path = "/http_server.py"
try:
f = open(curdir + sep + self.path)
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(f.read())
f.close()
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
def do_POST(self):
self.do_GET()
return
try:
server = HTTPServer(('', PORT_NUMBER), myHandler)
print 'Started httpserver on port ' , PORT_NUMBER
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()