(self)
| 310 | return |
| 311 | |
| 312 | def _parse_request(self): |
| 313 | # HTTP/1.1 connections are persistent by default. If a client |
| 314 | # requests a page, then idles (leaves the connection open), |
| 315 | # then rfile.readline() will raise socket.error("timed out"). |
| 316 | # Note that it does this based on the value given to settimeout(), |
| 317 | # and doesn't need the client to request or acknowledge the close |
| 318 | # (although your TCP stack might suffer for it: cf Apache's history |
| 319 | # with FIN_WAIT_2). |
| 320 | request_line = self.rfile.readline() |
| 321 | if not request_line: |
| 322 | # Force self.ready = False so the connection will close. |
| 323 | self.ready = False |
| 324 | return |
| 325 | |
| 326 | if request_line == "\r\n": |
| 327 | # RFC 2616 sec 4.1: "...if the server is reading the protocol |
| 328 | # stream at the beginning of a message and receives a CRLF |
| 329 | # first, it should ignore the CRLF." |
| 330 | # But only ignore one leading line! else we enable a DoS. |
| 331 | request_line = self.rfile.readline() |
| 332 | if not request_line: |
| 333 | self.ready = False |
| 334 | return |
| 335 | |
| 336 | environ = self.environ |
| 337 | |
| 338 | try: |
| 339 | method, path, req_protocol = request_line.strip().split(" ", 2) |
| 340 | except ValueError: |
| 341 | self.simple_response(400, "Malformed Request-Line") |
| 342 | return |
| 343 | |
| 344 | environ["REQUEST_METHOD"] = method |
| 345 | |
| 346 | # path may be an abs_path (including "http://host.domain.tld"); |
| 347 | scheme, location, path, params, qs, frag = urlparse(path) |
| 348 | |
| 349 | if frag: |
| 350 | self.simple_response("400 Bad Request", |
| 351 | "Illegal #fragment in Request-URI.") |
| 352 | return |
| 353 | |
| 354 | if scheme: |
| 355 | environ["wsgi.url_scheme"] = scheme |
| 356 | if params: |
| 357 | path = path + ";" + params |
| 358 | |
| 359 | environ["SCRIPT_NAME"] = "" |
| 360 | |
| 361 | # Unquote the path+params (e.g. "/this%20path" -> "this path"). |
| 362 | # http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2 |
| 363 | # |
| 364 | # But note that "...a URI must be separated into its components |
| 365 | # before the escaped characters within those components can be |
| 366 | # safely decoded." http://www.ietf.org/rfc/rfc2396.txt, sec 2.4.2 |
| 367 | atoms = [unquote(x) for x in quoted_slash.split(path)] |
| 368 | path = "%2F".join(atoms) |
| 369 | environ["PATH_INFO"] = path |
no test coverage detected