| 147 | |
| 148 | @classmethod |
| 149 | def parse(cls, raw): |
| 150 | altered = raw |
| 151 | comment = b"" |
| 152 | |
| 153 | if altered.startswith(b"HTTP response [") or altered.startswith(b"HTTP redirect ["): |
| 154 | stream = io.BytesIO(raw) |
| 155 | first_line = stream.readline() |
| 156 | parts = cls.extract_status.search(first_line) |
| 157 | status_line = "HTTP/1.0 %s %s" % (getText(parts.group(1)), getText(parts.group(2))) |
| 158 | remain = stream.read() |
| 159 | altered = getBytes(status_line) + b"\r\n" + remain |
| 160 | comment = first_line |
| 161 | |
| 162 | response = _http_client.HTTPResponse(FakeSocket(altered)) |
| 163 | response.begin() |
| 164 | |
| 165 | # NOTE: https://github.com/sqlmapproject/sqlmap/issues/5942 |
| 166 | response.length = len(raw[raw.find(b"\r\n\r\n") + 4:]) |
| 167 | |
| 168 | try: |
| 169 | content = response.read() |
| 170 | except _http_client.IncompleteRead: |
| 171 | content = raw[raw.find(b"\r\n\r\n") + 4:].rstrip(b"\r\n") |
| 172 | |
| 173 | return cls(httpVersion="HTTP/1.1" if response.version == 11 else "HTTP/1.0", |
| 174 | status=response.status, |
| 175 | statusText=response.reason, |
| 176 | headers=response.msg, |
| 177 | content=content, |
| 178 | comment=comment, |
| 179 | raw=raw) |
| 180 | |
| 181 | def toDict(self): |
| 182 | content = { |