httpx
httpx copied to clipboard
Corruption of query parameter value when using base_url with query string
- This issue is a follow-up of #3076
But it became a real problem if you try to set a query parameter within the base_url.
Test case:
import httpx
client = httpx.Client(base_url="https://httpbingo.org/get?data=1")
print(client.base_url.query)
response = client.get("")
print(response.json()["args"])
Expected output (as data is clearly defined as a query parameter)
b'data=1'
{'data': ['1']}
Other valid output (dropping query parameters)
b''
{}
Actual output
b'data=1/'
{'data': ['1/']}
Yep either of the two options you listed might be expected. The third, actual case is clearly invalid.
If I were redesigning this I would probably restrict the base_url to the scheme and domain portions.
Allowing a path portion is okayish, although somewhat ambiguous wrt expected join behaviours.
Allowing a query parameter portion is clearly problematic.