Read each request and respond appropriately.
(self)
| 1156 | self.environ["wsgi.input"] = SizeCheckWrapper(self.rfile, 0) |
| 1157 | |
| 1158 | def communicate(self): |
| 1159 | """Read each request and respond appropriately.""" |
| 1160 | try: |
| 1161 | while True: |
| 1162 | # (re)set req to None so that if something goes wrong in |
| 1163 | # the RequestHandlerClass constructor, the error doesn't |
| 1164 | # get written to the previous request. |
| 1165 | req = None |
| 1166 | req = self.RequestHandlerClass(self.wfile, self.environ, |
| 1167 | self.wsgi_app) |
| 1168 | |
| 1169 | # This order of operations should guarantee correct pipelining. |
| 1170 | req.parse_request() |
| 1171 | if not req.ready: |
| 1172 | return |
| 1173 | |
| 1174 | req.respond() |
| 1175 | if req.close_connection: |
| 1176 | return |
| 1177 | |
| 1178 | except socket.error, e: |
| 1179 | errnum = e.args[0] |
| 1180 | if errnum == 'timed out': |
| 1181 | if req and not req.sent_headers: |
| 1182 | req.simple_response("408 Request Timeout") |
| 1183 | elif errnum not in socket_errors_to_ignore: |
| 1184 | if req and not req.sent_headers: |
| 1185 | req.simple_response("500 Internal Server Error", |
| 1186 | format_exc()) |
| 1187 | return |
| 1188 | except (KeyboardInterrupt, SystemExit): |
| 1189 | raise |
| 1190 | except FatalSSLAlert, e: |
| 1191 | # Close the connection. |
| 1192 | return |
| 1193 | except NoSSLError: |
| 1194 | if req and not req.sent_headers: |
| 1195 | # Unwrap our wfile |
| 1196 | req.wfile = CP_fileobject(self.socket._sock, "wb", -1) |
| 1197 | req.simple_response("400 Bad Request", |
| 1198 | "The client sent a plain HTTP request, but " |
| 1199 | "this server only speaks HTTPS on this port.") |
| 1200 | self.linger = True |
| 1201 | except Exception, e: |
| 1202 | if req and not req.sent_headers: |
| 1203 | req.simple_response("500 Internal Server Error", format_exc()) |
| 1204 | |
| 1205 | linger = False |
| 1206 |
no test coverage detected