Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/h3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ async def send_http_request(self, url, method='GET', headers=None, content=None,
self._http._check_content_length = types.MethodType(
lambda self, stream: None, self._http)

path = (url.path or '/') + (f'?{url.query}' if url.query else '')
self.sent_headers = [
(b':method', method.encode()),
(b':scheme', b'https'),
(b':authority', url.hostname.encode()),
(b':path', (url.path or '/').encode()),
(b':path', path.encode()),
] + [(k.encode(), v.encode()) for k, v in (headers or {}).items()]

stream_id = self._quic.get_next_available_stream_id()
Expand Down
22 changes: 22 additions & 0 deletions tests/test_send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ def _connect(**kwargs):
self.assertEqual(calls[0]['port'], 443)


class TestRequestHeaders(unittest.TestCase):
def test_path_includes_query_string(self):
async def run():
client = h3mod.H3ClientProtocol.__new__(h3mod.H3ClientProtocol)
client._http = MagicMock()
client._quic = MagicMock()
client._quic.get_next_available_stream_id.return_value = 0
client._request_waiter = asyncio.get_running_loop().create_future()
client._request_waiter.set_result(True)
client.http_response_data = bytearray()
client.http_response_headers = {}
client.transmit = MagicMock()

await client.send_http_request(
urlparse('https://example.com/check?foo=bar&x=1')
)
headers = dict(client._http.send_headers.call_args.args[1])
self.assertEqual(headers[b':path'], b'/check?foo=bar&x=1')

asyncio.run(run())


# ---------------------------------------------------------------------------
# Tests: show-headers flag
# ---------------------------------------------------------------------------
Expand Down
Loading