9 from config import config, init_conf
11 from os import curdir, sep
12 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
14 import request_handler
16 class MyHandler(BaseHTTPRequestHandler):
24 length = int(self.headers.getheader('content-length'))
25 ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
26 if ctype != 'application/x-www-form-urlencoded':
27 log.error("request_handler_server: [%s]: 401 Unauthorized" % self.client_address[0])
32 query = self.rfile.read(length)
34 filename = self.headers.getheader('x-filename')
36 if not request_handler.handle_request_main(query, filename = filename):
37 log.error("request_handler_server: [%s]: handle_request_main(..., %s) failed" % (self.client_address[0], filename))
42 self.send_response(200)
48 log.error("request_handler_server: [%s]: exception: %s" % (self.client_address[0], e))
53 socket.setdefaulttimeout(30)
57 port = config.request_handler_server_port
60 server = HTTPServer((host, port), MyHandler)
62 log.notice("request_handler_server: can't start server on [%s:%d]: %s" % (host, port, e))
63 print >> sys.stderr, "ERROR: Can't start server on [%s:%d]: %s" % (host, port, e)
66 log.notice('request_handler_server: started on [%s:%d]...' % (host, port))
67 server.serve_forever()
68 except KeyboardInterrupt:
69 log.notice('request_handler_server: ^C received, shutting down server')
72 if __name__ == '__main__':