| | 203 | |
|---|
| | 204 | # Server3 components # |
|---|
| | 205 | |
|---|
| | 206 | |
|---|
| | 207 | class CPHTTPRequest3(_cpwsgiserver3.HTTPRequest): |
|---|
| | 208 | |
|---|
| | 209 | def parse_request(self): |
|---|
| | 210 | mhs = int(cherrypy.config.get('server.max_request_header_size', |
|---|
| | 211 | 500 * 1024)) |
|---|
| | 212 | if mhs > 0: |
|---|
| | 213 | self.rfile = httptools.SizeCheckWrapper(self.rfile, mhs) |
|---|
| | 214 | |
|---|
| | 215 | try: |
|---|
| | 216 | _cpwsgiserver3.HTTPRequest.parse_request(self) |
|---|
| | 217 | except httptools.MaxSizeExceeded: |
|---|
| | 218 | self.simple_response("413 Request Entity Too Large") |
|---|
| | 219 | cherrypy.log(traceback=True) |
|---|
| | 220 | else: |
|---|
| | 221 | if self.ready: |
|---|
| | 222 | if isinstance(self.rfile, httptools.SizeCheckWrapper): |
|---|
| | 223 | # Unwrap the rfile |
|---|
| | 224 | self.rfile = self.rfile.rfile |
|---|
| | 225 | self.environ["wsgi.input"] = self.rfile |
|---|
| | 226 | |
|---|
| | 227 | def decode_chunked(self): |
|---|
| | 228 | """Decode the 'chunked' transfer coding.""" |
|---|
| | 229 | if isinstance(self.rfile, httptools.SizeCheckWrapper): |
|---|
| | 230 | self.rfile = self.rfile.rfile |
|---|
| | 231 | mbs = int(cherrypy.config.get('server.max_request_body_size', |
|---|
| | 232 | 100 * 1024 * 1024)) |
|---|
| | 233 | if mbs > 0: |
|---|
| | 234 | self.rfile = httptools.SizeCheckWrapper(self.rfile, mbs) |
|---|
| | 235 | try: |
|---|
| | 236 | return _cpwsgiserver3.HTTPRequest.decode_chunked(self) |
|---|
| | 237 | except httptools.MaxSizeExceeded: |
|---|
| | 238 | self.simple_response("413 Request Entity Too Large") |
|---|
| | 239 | cherrypy.log(traceback=True) |
|---|
| | 240 | return False |
|---|
| | 241 | |
|---|
| | 242 | |
|---|
| | 243 | class CPHTTPConnection3(_cpwsgiserver3.HTTPConnection): |
|---|
| | 244 | |
|---|
| | 245 | RequestHandlerClass = CPHTTPRequest3 |
|---|
| | 246 | |
|---|
| | 247 | |
|---|
| | 248 | class CPWSGIServer3(_cpwsgiserver3.CherryPyWSGIServer): |
|---|
| | 249 | """Wrapper for _cpwsgiserver3.CherryPyWSGIServer. |
|---|
| | 250 | |
|---|
| | 251 | wsgiserver has been designed to not reference CherryPy in any way, |
|---|
| | 252 | so that it can be used in other frameworks and applications. Therefore, |
|---|
| | 253 | we wrap it here, so we can set our own mount points from cherrypy.tree. |
|---|
| | 254 | """ |
|---|
| | 255 | |
|---|
| | 256 | ConnectionClass = CPHTTPConnection3 |
|---|
| | 257 | |
|---|
| | 258 | def __init__(self): |
|---|
| | 259 | conf = cherrypy.config.get |
|---|
| | 260 | |
|---|
| | 261 | sockFile = cherrypy.config.get('server.socket_file') |
|---|
| | 262 | if sockFile: |
|---|
| | 263 | bind_addr = sockFile |
|---|
| | 264 | else: |
|---|
| | 265 | bind_addr = (conf("server.socket_host"), conf("server.socket_port")) |
|---|
| | 266 | |
|---|
| | 267 | pts = cherrypy.tree.mount_points |
|---|
| | 268 | if pts: |
|---|
| | 269 | apps = [(base, wsgiApp) for base in pts.keys()] |
|---|
| | 270 | else: |
|---|
| | 271 | apps = [("", wsgiApp)] |
|---|
| | 272 | |
|---|
| | 273 | s = _cpwsgiserver3.CherryPyWSGIServer |
|---|
| | 274 | s.__init__(self, bind_addr, apps, |
|---|
| | 275 | conf("server.thread_pool"), |
|---|
| | 276 | conf("server.socket_host"), |
|---|
| | 277 | request_queue_size = conf('server.socket_queue_size'), |
|---|
| | 278 | timeout = conf('server.socket_timeout'), |
|---|
| | 279 | ) |
|---|
| | 280 | |
|---|
| | 281 | self.protocol = conf("server.protocol_version") |
|---|
| | 282 | self.ssl_certificate = conf("server.ssl_certificate") |
|---|
| | 283 | self.ssl_private_key = conf("server.ssl_private_key") |
|---|
| | 284 | |
|---|