| 70 | | |
|---|
| 71 | | try: |
|---|
| 72 | | self.request = self.get_request(environ) |
|---|
| 73 | | |
|---|
| 74 | | meth = environ['REQUEST_METHOD'] |
|---|
| 75 | | path = _http.urljoin(environ.get('SCRIPT_NAME', ''), |
|---|
| 76 | | environ.get('PATH_INFO', '')) |
|---|
| 77 | | qs = environ.get('QUERY_STRING', '') |
|---|
| 78 | | rproto = environ.get('SERVER_PROTOCOL') |
|---|
| 79 | | headers = self.translate_headers(environ) |
|---|
| 80 | | rfile = environ['wsgi.input'] |
|---|
| 81 | | |
|---|
| 82 | | response = self.request.run(meth, path, qs, rproto, headers, rfile) |
|---|
| 83 | | s, h, b = response.status, response.header_list, response.body |
|---|
| | 74 | self.setapp() |
|---|
| | 75 | |
|---|
| | 76 | def setapp(self): |
|---|
| | 77 | # Stage 1: by whatever means necessary, obtain a status, header |
|---|
| | 78 | # set and body, with an optional exception object. |
|---|
| | 79 | try: |
|---|
| | 80 | self.request = self.get_request() |
|---|
| | 81 | s, h, b = self.get_response() |
|---|
| | 125 | |
|---|
| | 126 | def iredirect(self, path, query_string): |
|---|
| | 127 | """Doctor self.environ and perform an internal redirect. |
|---|
| | 128 | |
|---|
| | 129 | When cherrypy.InternalRedirect is raised, this method is called. |
|---|
| | 130 | It rewrites the WSGI environ using the new path and query_string, |
|---|
| | 131 | and calls a new CherryPy Request object. Because the wsgi.input |
|---|
| | 132 | stream may have already been consumed by the next application, |
|---|
| | 133 | the redirected call will always be of HTTP method "GET"; therefore, |
|---|
| | 134 | any params must be passed in the query_string argument, which is |
|---|
| | 135 | formed from InternalRedirect.query_string when using that exception. |
|---|
| | 136 | If you need something more complicated, make and raise your own |
|---|
| | 137 | exception and write your own AppResponse subclass to trap it. ;) |
|---|
| | 138 | |
|---|
| | 139 | It would be a bad idea to redirect after you've already yielded |
|---|
| | 140 | response content, although an enterprising soul could choose |
|---|
| | 141 | to abuse this. |
|---|
| | 142 | """ |
|---|
| | 143 | env = self.environ |
|---|
| | 144 | if not self.recursive: |
|---|
| | 145 | sn = env.get('SCRIPT_NAME', '') |
|---|
| | 146 | qs = query_string |
|---|
| | 147 | if qs: |
|---|
| | 148 | qs = "?" + qs |
|---|
| | 149 | if sn + path + qs in self.redirections: |
|---|
| | 150 | raise RuntimeError("InternalRedirector visited the " |
|---|
| | 151 | "same URL twice: %r + %r + %r" % |
|---|
| | 152 | (sn, path, qs)) |
|---|
| | 153 | else: |
|---|
| | 154 | # Add the *previous* path_info + qs to redirections. |
|---|
| | 155 | p = env.get('PATH_INFO', '') |
|---|
| | 156 | qs = env.get('QUERY_STRING', '') |
|---|
| | 157 | if qs: |
|---|
| | 158 | qs = "?" + qs |
|---|
| | 159 | self.redirections.append(sn + p + qs) |
|---|
| | 160 | |
|---|
| | 161 | # Munge environment and try again. |
|---|
| | 162 | env['REQUEST_METHOD'] = "GET" |
|---|
| | 163 | env['PATH_INFO'] = path |
|---|
| | 164 | env['QUERY_STRING'] = query_string |
|---|
| | 165 | env['wsgi.input'] = _StringIO.StringIO() |
|---|
| | 166 | env['CONTENT_LENGTH'] = "0" |
|---|
| | 167 | |
|---|
| | 168 | self.setapp() |
|---|
| 154 | | def get_request(self, environ): |
|---|
| | 209 | def get_response(self): |
|---|
| | 210 | """Grab a request object from the engine and return its response.""" |
|---|
| | 211 | meth = self.environ['REQUEST_METHOD'] |
|---|
| | 212 | path = _http.urljoin(self.environ.get('SCRIPT_NAME', ''), |
|---|
| | 213 | self.environ.get('PATH_INFO', '')) |
|---|
| | 214 | qs = self.environ.get('QUERY_STRING', '') |
|---|
| | 215 | rproto = self.environ.get('SERVER_PROTOCOL') |
|---|
| | 216 | headers = self.translate_headers(self.environ) |
|---|
| | 217 | rfile = self.environ['wsgi.input'] |
|---|
| | 218 | response = self.request.run(meth, path, qs, rproto, headers, rfile) |
|---|
| | 219 | return response.status, response.header_list, response.body |
|---|
| | 220 | |
|---|
| | 221 | def get_request(self): |
|---|
| 171 | | request.multithread = environ['wsgi.multithread'] |
|---|
| 172 | | request.multiprocess = environ['wsgi.multiprocess'] |
|---|
| 173 | | request.wsgi_environ = environ |
|---|
| 174 | | request.prev = env('cherrypy.request') |
|---|
| 175 | | environ['cherrypy.request'] = request |
|---|
| | 238 | request.multithread = self.environ['wsgi.multithread'] |
|---|
| | 239 | request.multiprocess = self.environ['wsgi.multiprocess'] |
|---|
| | 240 | request.wsgi_environ = self.environ |
|---|
| | 241 | request.prev = env('cherrypy.previous_request', None) |
|---|