Propagate path prefix in server URLs to all requests #771
+28
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of the changes / Why this is an improvement
Path prefixes in server URLs are now propagated to all requests.
E.g. if the server URL 'http://my-server:1234/crate/' is supplied, requests with SQL queries will be sent to 'http://my-server:1234/crate/_sql?types=true'. Currently, the prefix would be ignored, resulting in 'http://my-server:1234/_sql?types=true' for the same server URL input.
I've encountered multiple setups with proxies that handle forwarding based on path prefixes. This change makes the client work in such setups.
One aspect I'm unsure about:
crate-python/tests/client/test_http.py
Lines 238 to 239 in 7ec1b56
Seems like you don't want the client to crash if
urllib.parse.urlparsethrows an exception, so I wrapped my call in a try-except block:https://github.com/Kleinjohann/crate-python/blob/d5a7902f44f920646dfe0b19884fc0a635879d19/src/crate/client/http.py#L147-L155
This might however just move unavoidable errors to later stages where they will result in less meaningful error messages. The only hint to anyone trying to debug this would be the warning in the log.
I'm probably missing something here, and it's fine for me to keep it as is, I just somehow didn't feel comfortable implementing it like this.
Fixes #743