Takes a HTTP packet, and returns a tuple containing: _ the first line (e.g., "GET ...") _ the headers in a dictionary _ the body
(s)
| 256 | |
| 257 | |
| 258 | def _parse_headers_and_body(s): |
| 259 | """Takes a HTTP packet, and returns a tuple containing: |
| 260 | _ the first line (e.g., "GET ...") |
| 261 | _ the headers in a dictionary |
| 262 | _ the body |
| 263 | """ |
| 264 | crlfcrlf = b"\r\n\r\n" |
| 265 | crlfcrlfIndex = s.find(crlfcrlf) |
| 266 | if crlfcrlfIndex != -1: |
| 267 | headers = s[: crlfcrlfIndex + len(crlfcrlf)] |
| 268 | body = s[crlfcrlfIndex + len(crlfcrlf) :] |
| 269 | else: |
| 270 | headers = s |
| 271 | body = b"" |
| 272 | first_line, headers = headers.split(b"\r\n", 1) |
| 273 | return first_line.strip(), _parse_headers(headers), body |
| 274 | |
| 275 | |
| 276 | def _dissect_headers(obj, s): |
no test coverage detected
searching dependent graphs…