Return either the request or response if only one exists, otherwise return both
(f: flow.Flow, separator=b"\r\n\r\n")
| 133 | |
| 134 | |
| 135 | def raw(f: flow.Flow, separator=b"\r\n\r\n") -> bytes: |
| 136 | """Return either the request or response if only one exists, otherwise return both""" |
| 137 | request_present = ( |
| 138 | isinstance(f, http.HTTPFlow) and f.request and f.request.raw_content is not None |
| 139 | ) |
| 140 | response_present = ( |
| 141 | isinstance(f, http.HTTPFlow) |
| 142 | and f.response |
| 143 | and f.response.raw_content is not None |
| 144 | ) |
| 145 | |
| 146 | if request_present and response_present: |
| 147 | parts = [raw_request(f), raw_response(f)] |
| 148 | if isinstance(f, http.HTTPFlow) and f.websocket: |
| 149 | parts.append(f.websocket._get_formatted_messages()) |
| 150 | return separator.join(parts) |
| 151 | elif request_present: |
| 152 | return raw_request(f) |
| 153 | elif response_present: |
| 154 | return raw_response(f) |
| 155 | else: |
| 156 | raise exceptions.CommandError("Can't export flow with no request or response.") |
| 157 | |
| 158 | |
| 159 | formats: dict[str, Callable[[flow.Flow], str | bytes]] = dict( |
no test coverage detected