Created
January 12, 2012 15:48
-
-
Save munhitsu/1601216 to your computer and use it in GitHub Desktop.
Simple WSGI application that handles POST - for testing/debuging of PROXY
This file contains hidden or 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
from wsgiref.util import setup_testing_defaults, FileWrapper | |
from wsgiref.simple_server import make_server | |
import sys | |
from pprint import pprint | |
# A relatively simple WSGI application. It's going to print out the | |
# environment dictionary after being updated by setup_testing_defaults | |
def simple_app(environ, start_response): | |
setup_testing_defaults(environ) | |
if environ['REQUEST_METHOD'] == 'POST' or environ['REQUEST_METHOD'] == 'PUT' : | |
bsize = 1024*1024 | |
length = int(environ['CONTENT_LENGTH']) | |
# result = FileWrapper(environ['wsgi.input'], blksize=bsize) | |
bsizes = [bsize for x in xrange(bsize, length, bsize)] | |
bsizes.append(length-len(bsizes)*bsize) | |
input = environ['wsgi.input'] | |
for thissize in bsizes: | |
input.read(thissize) | |
sys.stdout.write(".") | |
sys.stdout.flush() | |
print "" | |
if hasattr(input, 'close'): | |
print "closing the input" | |
input.close() | |
status = '200 OK' | |
headers = [('Content-type', 'text/plain')] | |
start_response(status, headers) | |
ret = ["%s: %s\n" % (key, value) | |
for key, value in environ.iteritems()] | |
pprint(ret) | |
return ret | |
httpd = make_server('', 8888, simple_app) | |
print "Serving on port 8888..." | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment