Fix HttpHook double slash in URL when connection host has trailing slash and endpoint has leading slash - #71660
Draft
aryansk wants to merge 1 commit into
Draft
Conversation
…t both have slashes When a connection host is configured with a trailing slash and the endpoint starts with a leading slash (both common), the resulting URL contained a double slash (e.g. https://api.example.com/v1//users). Many API frameworks do not normalize `//` in paths and return 404, producing a silent, confusing failure. Join base_url and endpoint with exactly one slash in all cases. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes #71658
What is changing and why
HttpHook._url_from_endpoint()(used by bothHttpHookandHttpAsyncHook) only guarded against a missing slash betweenbase_urlandendpoint— it did not guard against a double one. When a connection host is configured with a trailing/(common) and an endpoint is passed with a leading/(also common REST convention), the resulting URL contained//:Many API frameworks (Flask, FastAPI, Django) do not normalize
//in a path and return 404, so this produced a silent, confusing failure.The fix joins
base_urlandendpointwith exactly one/in all cases, preserving the existing behavior for every other input combination (including scheme-only base URLs such ashttp://, and endpoint-only requests).Tests
test_url_from_endpointcovering trailing-slash, leading-slash, and both.providers/http/tests/unit/http/hooks/test_http.py: 60 passed, 1 pre-existing environment error (verified identical onmain).ruff checkandruff format --checkclean on both changed files.