| 75 | | # Reconstruct the wsgi.input stream from req.args, so dispatch_request |
|---|
| 76 | | # can read it again. If we don't do this, POST data gets lost because |
|---|
| 77 | | # the original stream has already been read once. |
|---|
| 78 | | if environ['wsgi.input']: |
|---|
| 79 | | args = {} |
|---|
| 80 | | for k,v in req.args.iteritems(): |
|---|
| 81 | | if isinstance(v, unicode): |
|---|
| 82 | | v = v.encode('utf-8') |
|---|
| 83 | | args[k] = v |
|---|
| 84 | | data = urllib.urlencode(args) |
|---|
| 85 | | class InputStream: |
|---|
| 86 | | def __init__(self, data): |
|---|
| 87 | | self.data = data |
|---|
| 88 | | def read(self, size=None): |
|---|
| 89 | | result = self.data[:size] |
|---|
| 90 | | self.data = self.data[size:] |
|---|
| 91 | | return result |
|---|
| 92 | | |
|---|
| 93 | | environ['wsgi.input'] = InputStream(data) |
|---|
| 94 | | # This doesn't match up sometimes. Don't know why yet. |
|---|
| 95 | | environ['CONTENT_LENGTH'] = len(data) |
|---|
| 96 | | |
|---|