| 510 | |
| 511 | |
| 512 | class HTTPRequest(_HTTPContent): |
| 513 | name = "HTTP Request" |
| 514 | fields_desc = ( |
| 515 | [ |
| 516 | # First line |
| 517 | _HTTPHeaderField("Method", "GET"), |
| 518 | _HTTPHeaderField("Path", "/"), |
| 519 | _HTTPHeaderField("Http-Version", "HTTP/1.1"), |
| 520 | # Headers |
| 521 | ] |
| 522 | + ( |
| 523 | _generate_headers( |
| 524 | GENERAL_HEADERS, |
| 525 | REQUEST_HEADERS, |
| 526 | COMMON_UNSTANDARD_GENERAL_HEADERS, |
| 527 | COMMON_UNSTANDARD_REQUEST_HEADERS, |
| 528 | ) |
| 529 | ) |
| 530 | + [ |
| 531 | _HTTPHeaderField("Unknown-Headers", None), |
| 532 | ] |
| 533 | ) |
| 534 | |
| 535 | def do_dissect(self, s): |
| 536 | """From the HTTP packet string, populate the scapy object""" |
| 537 | first_line, body = _dissect_headers(self, s) |
| 538 | try: |
| 539 | Method, Path, HTTPVersion = re.split(rb"\s+", first_line, maxsplit=2) |
| 540 | self.setfieldval("Method", Method) |
| 541 | self.setfieldval("Path", Path) |
| 542 | self.setfieldval("Http_Version", HTTPVersion) |
| 543 | except ValueError: |
| 544 | pass |
| 545 | if body: |
| 546 | self.raw_packet_cache = s[: -len(body)] |
| 547 | else: |
| 548 | self.raw_packet_cache = s |
| 549 | return body |
| 550 | |
| 551 | def mysummary(self): |
| 552 | return self.sprintf("%HTTPRequest.Method% '%HTTPRequest.Path%' ") |
| 553 | |
| 554 | |
| 555 | class HTTPResponse(_HTTPContent): |
no test coverage detected