54 lines
1.1 KiB
Python
54 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
from gevent import monkey
|
|
monkey.patch_all()
|
|
import urllib
|
|
import urllib2
|
|
import sys
|
|
import traceback
|
|
from cgi import escape
|
|
|
|
|
|
from gevent.pywsgi import WSGIServer
|
|
import poster.streaminghttp
|
|
|
|
opener = poster.streaminghttp.register_openers()
|
|
|
|
# TODO: create a true configuration file
|
|
drop_headers = ['transfer-encoding']
|
|
|
|
|
|
class RpRedirectHandler(urllib2.HTTPRedirectHandler):
|
|
|
|
def http_error_302(self, req, fp, code, msg, headers):
|
|
""" Disable the auto """
|
|
infourl = urllib.addinfourl(fp, headers, req.get_full_url())
|
|
infourl.code = code
|
|
infourl.msg = msg
|
|
return infourl
|
|
|
|
class DefaultErrorHandler(urllib2.HTTPDefaultErrorHandler):
|
|
def http_error_default(self, req, fp, code, msg, headers):
|
|
result = urllib2.HTTPError(req.get_full_url(), code, msg, headers, fp)
|
|
result.status = code
|
|
return result
|
|
|
|
|
|
|
|
|
|
def serve(host,port):
|
|
"""Convenience function to immediately start a server instance."""
|
|
s = WSGIServer((host, port), RequestApp(config))
|
|
s.serve_forever()
|
|
|
|
|
|
def _demo():
|
|
serve('localhost', 8088)
|
|
|
|
if __name__ == "__main__":
|
|
_demo()
|
|
|
|
|