public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Fixed bug that POST data isn't available in Django. Needed CONTENT_LENGTH 
and file-like methods for the wsgi.input
Weyert de Boer (author)
Sat Jun 28 19:35:27 -0700 2008
commit  3e4a328b76b8d18fb6390bb428d9fce5666fb985
tree    346f9790df691c3929d2d169f1a1f8a26535630b
parent  c7283e5f09b30381c0e8dff5587176c1e22d1fae
...
2
3
4
 
 
5
6
7
...
71
72
73
74
75
76
77
 
 
 
 
 
 
 
 
 
 
 
78
79
 
80
81
82
83
 
 
 
 
 
 
 
84
85
86
...
136
137
138
139
 
140
...
2
3
4
5
6
7
8
9
...
73
74
75
 
 
 
 
76
77
78
79
80
81
82
83
84
85
86
87
 
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
152
153
154
 
155
156
0
@@ -2,6 +2,8 @@
0
 import socket, os, random, sys, struct, select, imp
0
 import exceptions, traceback
0
 
0
+from socket import _fileobject
0
+
0
 class RequestHandler:
0
   def __init__(self, socket_file, server, owner_pipe, app):
0
     self.socket_file = socket_file
0
@@ -71,16 +73,30 @@ class RequestHandler:
0
     return (env, client)
0
   
0
   def process_request(self, env, input_stream, output_stream):
0
- env['wsgi.input'] = input_stream
0
- env['wsgi.errors'] = sys.stderr
0
- env['wsgi.version'] = (1, 0)
0
- env['wsgi.multithread'] = False
0
+ # The WSGI speculation says that the input paramter object passed needs to
0
+ # implement a few file-like methods. This is the reason why we "wrap" the socket._socket
0
+ # into the _fileobject to solve this.
0
+ #
0
+ # Otherwise, the POST data won't be correctly retrieved by Django.
0
+ #
0
+ # See: http://www.python.org/dev/peps/pep-0333/#input-and-error-streams
0
+ env['wsgi.input'] = _fileobject(input_stream,'r',512)
0
+ env['wsgi.errors'] = sys.stderr
0
+ env['wsgi.version'] = (1, 0)
0
+ env['wsgi.multithread'] = False
0
     env['wsgi.multiprocess'] = True
0
- env['wsgi.run_once'] = True
0
+ env['wsgi.run_once'] = True
0
     if env.get('HTTPS','off') in ('on', '1'):
0
       env['wsgi.url_scheme'] = 'https'
0
     else:
0
       env['wsgi.url_scheme'] = 'http'
0
+
0
+
0
+ # The following environment variables are required by WSCI PEP #333
0
+ # see: http://www.python.org/dev/peps/pep-0333/#environ-variables
0
+ if 'HTTP_CONTENT_LENGTH' in env:
0
+ env['CONTENT_LENGTH'] = env.get('HTTP_CONTENT_LENGTH')
0
+
0
     
0
     headers_set = []
0
     headers_sent = []
0
@@ -136,4 +152,4 @@ if __name__ == "__main__":
0
   try:
0
     handler.main_loop()
0
   finally:
0
- handler.cleanup()
0
+ handler.cleanup()
0
\ No newline at end of file

Comments

    No one has commented yet.