(self, lines)
| 161 | ) |
| 162 | |
| 163 | def parse_response(self, lines) -> ExecResult: |
| 164 | exp_body = False |
| 165 | exp_stat = True |
| 166 | r = ExecResult(args=[], exit_code=0, stdout=b'', stderr=b'') |
| 167 | header = {} |
| 168 | body = [] |
| 169 | for line in lines: |
| 170 | if exp_stat: |
| 171 | m = re.match(r'^(\S+) (\d+) (.*)$', line) |
| 172 | assert m, f"first line no HTTP status line: {line}" |
| 173 | r.add_response({ |
| 174 | "protocol": m.group(1), |
| 175 | "status": int(m.group(2)), |
| 176 | "description": m.group(3), |
| 177 | "body": r.outraw |
| 178 | }) |
| 179 | header = {} |
| 180 | exp_stat = False |
| 181 | exp_body = False |
| 182 | elif re.match(r'^\r?$', line): |
| 183 | exp_body = True |
| 184 | elif exp_body: |
| 185 | body.append(line) |
| 186 | else: |
| 187 | m = re.match(r'^([^:]+):\s*(.*)$', line) |
| 188 | assert m, f"not a header line: {line}" |
| 189 | header[m.group(1).lower()] = m.group(2) |
| 190 | if r.response: |
| 191 | r.response["header"] = header |
| 192 | r.response["body"] = body |
| 193 | return r |
no test coverage detected