Skip to content

Commit

Permalink
Added basic handling of POST requests. Need to figure out better way.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjshields committed Feb 4, 2015
1 parent 0ee14b2 commit 3d2ad54
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tiny.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import re
import cgi

def wsgiref_server(app, host='', port=8080):
"""Implements a WSGIref server and serves continuously.
Expand Down Expand Up @@ -53,8 +54,16 @@ def request_handler(environ, start_response):
else:
queries = None

# FIX: Implement routing more intelligently than a conditional statement.
# FIX: Figure out how to deal w/ POST requests and parse their data.
if content_length:
content = environ.get('wsgi.input').read(int(content_length))
print content

if method == 'POST':
form = cgi.FieldStorage()
print form.getvalue('name')

# URL Routing
if path not in URLS:
# Status, headers represent the HTTP response expected by the client.
status = '404 NOT FOUND'
Expand Down Expand Up @@ -94,7 +103,7 @@ def index(environ):
return 'Home'

def jim(environ):
return 'Jim'
return '<form method="POST"><input type="text" name="name"><input type="text" name="movie"><input type="submit"></form>'

# URLS

Expand Down

0 comments on commit 3d2ad54

Please sign in to comment.