Created
September 10, 2010 18:59
-
-
Save dsedivec/574160 to your computer and use it in GitHub Desktop.
This file contains 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
In one window: | |
$ python2.6 /tmp/wsgiexample.py | |
In another: | |
$ curl http://localhost:9977 | |
POST some text to me. | |
$ curl -d 'This is xxx a test.' http://localhost:9977 | |
I found 3 X(es). |
This file contains 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.simple_server import make_server | |
def count_letter_x(environ, start_response): | |
start_response("200 OK", [("Content-Type", "text/plain")]) | |
if environ["REQUEST_METHOD"] == "POST": | |
length = environ["CONTENT_LENGTH"] | |
request_body = environ["wsgi.input"].read(int(length)) | |
num_x_letters = request_body.count("x") | |
return ["I found %d X(es).\n" % (num_x_letters,)] | |
else: | |
return ["POST some text to me.\n"] | |
server = make_server("", 9977, count_letter_x) | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment