Skip to content

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
apache:mainfrom
aryansk:fix-http-hook-double-slash-71658
Draft

Fix HttpHook double slash in URL when connection host has trailing slash and endpoint has leading slash#71660
aryansk wants to merge 1 commit into
apache:mainfrom
aryansk:fix-http-hook-double-slash-71658

Conversation

@aryansk

@aryansk aryansk commented Aug 15, 2026

Copy link
Copy Markdown

closes #71658

What is changing and why

HttpHook._url_from_endpoint() (used by both HttpHook and HttpAsyncHook) only guarded against a missing slash between base_url and endpoint — 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 //:

hook.base_url = "https://api.example.com/v1/"
hook.url_from_endpoint("/users")
# before: https://api.example.com/v1//users
# after:  https://api.example.com/v1/users

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_url and endpoint with exactly one / in all cases, preserving the existing behavior for every other input combination (including scheme-only base URLs such as http://, and endpoint-only requests).

Tests

  • Added parametrized regression cases to test_url_from_endpoint covering trailing-slash, leading-slash, and both.
  • providers/http/tests/unit/http/hooks/test_http.py: 60 passed, 1 pre-existing environment error (verified identical on main).
  • ruff check and ruff format --check clean on both changed files.

…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>
@boring-cyborg

boring-cyborg Bot commented Aug 15, 2026

Copy link
Copy Markdown

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
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpHook: double slash in URL when connection host has trailing slash and endpoint has leading slash

1 participant