| 70 | return self._run(self.complete_args(url, timeout, options)) |
| 71 | |
| 72 | def parse_output(self, btext) -> Dict: |
| 73 | # getting meta data and response body out of nghttp's output |
| 74 | # is a bit tricky. Without '-v' we just get the body. With '-v' meta |
| 75 | # data and timings in both directions are listed. |
| 76 | # We rely on response :status: to be unique and on |
| 77 | # response body not starting with space. |
| 78 | # Something not good enough for general purpose, but for these tests. |
| 79 | output = {} |
| 80 | body = '' |
| 81 | streams = {} |
| 82 | skip_indents = True |
| 83 | # chunk output into lines. nghttp mixes text |
| 84 | # meta output with bytes from the response body. |
| 85 | lines = [l.decode() for l in btext.split(b'\n')] |
| 86 | |
| 87 | for lidx, l in enumerate(lines): |
| 88 | if len(l) == 0: |
| 89 | body += '\n' |
| 90 | continue |
| 91 | m = re.match(r'(.*)\[.*] recv \(stream_id=(\d+)\) (\S+): (\S*)', l) |
| 92 | if m: |
| 93 | body += m.group(1) |
| 94 | s = self.get_stream(streams, m.group(2)) |
| 95 | hname = m.group(3) |
| 96 | hval = m.group(4) |
| 97 | print("stream %d header %s: %s" % (s["id"], hname, hval)) |
| 98 | header = s["header"] |
| 99 | if hname in header: |
| 100 | header[hname] += ", %s" % hval |
| 101 | else: |
| 102 | header[hname] = hval |
| 103 | continue |
| 104 | |
| 105 | m = re.match(r'(.*)\[.*] recv HEADERS frame <.* stream_id=(\d+)>', l) |
| 106 | if m: |
| 107 | body += m.group(1) |
| 108 | s = self.get_stream(streams, m.group(2)) |
| 109 | if s: |
| 110 | print("stream %d: recv %d header" % (s["id"], len(s["header"]))) |
| 111 | response = s["response"] |
| 112 | hkey = "header" |
| 113 | if "header" in response: |
| 114 | h = response["header"] |
| 115 | if ":status" in h and int(h[":status"]) >= 200: |
| 116 | hkey = "trailer" |
| 117 | else: |
| 118 | prev = { |
| 119 | "header": h |
| 120 | } |
| 121 | if "previous" in response: |
| 122 | prev["previous"] = response["previous"] |
| 123 | response["previous"] = prev |
| 124 | response[hkey] = s["header"] |
| 125 | s["header"] = {} |
| 126 | body = '' |
| 127 | continue |
| 128 | |
| 129 | m = re.match(r'(.*)\[.*] recv DATA frame <length=(\d+), .*stream_id=(\d+)>', l) |