|
14 | 14 | from roundup.cgi import TranslationService |
15 | 15 | from roundup.anypy import http_ |
16 | 16 | from roundup.anypy.strings import s2b, bs2b |
| 17 | + |
| 18 | +from roundup.cgi.client import BinaryFieldStorage |
| 19 | + |
17 | 20 | BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler |
18 | 21 | DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE |
19 | 22 |
|
@@ -69,21 +72,33 @@ def __call__(self, environ, start_response): |
69 | 72 | request.headers = Headers(environ) |
70 | 73 |
|
71 | 74 | if environ ['REQUEST_METHOD'] == 'OPTIONS': |
72 | | - code = 501 |
73 | | - message, explain = BaseHTTPRequestHandler.responses[code] |
74 | | - request.start_response([('Content-Type', 'text/html'), |
75 | | - ('Connection', 'close')], code) |
76 | | - request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals())) |
77 | | - return [] |
78 | | - |
| 75 | + if environ["PATH_INFO"][:5] == "/rest": |
| 76 | + # rest does support options |
| 77 | + # This I hope will result in self.form=None |
| 78 | + environ['CONTENT_LENGTH'] = 0 |
| 79 | + else: |
| 80 | + code = 501 |
| 81 | + message, explain = BaseHTTPRequestHandler.responses[code] |
| 82 | + request.start_response([('Content-Type', 'text/html'), |
| 83 | + ('Connection', 'close')], code) |
| 84 | + request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals())) |
| 85 | + return [] |
| 86 | + |
79 | 87 | tracker = roundup.instance.open(self.home, not self.debug) |
80 | 88 |
|
81 | 89 | # need to strip the leading '/' |
82 | 90 | environ["PATH_INFO"] = environ["PATH_INFO"][1:] |
83 | 91 | if request.timing: |
84 | 92 | environ["CGI_SHOW_TIMING"] = request.timing |
85 | 93 |
|
86 | | - form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) |
| 94 | + form = BinaryFieldStorage(fp=environ['wsgi.input'], environ=environ) |
| 95 | + |
| 96 | + if environ ['REQUEST_METHOD'] in ("OPTIONS", "DELETE"): |
| 97 | + # these methods have no data. When we init tracker.Client |
| 98 | + # set form to None and request.rfile to None to get a |
| 99 | + # properly initialized empty form. |
| 100 | + form = None |
| 101 | + request.rfile = None |
87 | 102 |
|
88 | 103 | client = tracker.Client(tracker, request, environ, form, |
89 | 104 | request.translator) |
|
0 commit comments