HttpHook: double slash in URL when connection host has trailing slash and endpoint has leading slash
- Dominant language
- Python
- Stars
- 46.9k
- Forks
- 17.8k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 472
Description
### Under which category would you file this issue?
Providers
### Apache Airflow version
main (development)
### What happened and how to reproduce it?
`HttpHook._url_from_endpoint()` (in `providers/http/src/airflow/providers/http/hooks/http.py`) only guards against a *missing* slash between `base_url` and `endpoint` — it doesn't guard against a *double* one. If a connection's host is configured with a trailing `/` (common) and an endpoint is passed with a leading `/` (also common REST convention), the resulting URL has `//` in it.
Repro:
```python
from airflow.providers.http.hooks.http import HttpHook
hook = HttpHook()
hook.base_url = "https://api.example.com/v1/"
hook._base_url_initialized = True
print(hook.url_from_endpoint("/users"))
# https://api.example.com/v1//users <- double slash
```
Many API frameworks (Flask, FastAPI, Django) do not normalize `//` in a path and will 404 on it, so this produces a silent, confusing failure for anyone hitting this combination. Affects both `HttpHook` and `HttpAsyncHook`, since both call the shared `_url_from_endpoint()` helper.
### What you think should happen instead?
Exactly one `/` should separate the base URL and endpoint regardless of which side(s) already have a slash. `_url_from_endpoint()` should strip the trailing slash from `base_url` and the leading slash from `endpoint` before joining, rather than only checking for the missing-slash case.
Happy to open a PR with the fix and a test covering this slash combination — will link it here.
### Operating System
_No response_
### Deployment
None
### Apache Airflow Provider(s)
http
### Versions of Apache Airflow Providers
_No response_
### Official Helm Chart version
Not Applicable
### Kubernetes Version
_No response_
### Helm Chart configuration
_No response_
### Docker Image customizations
_No response_
### Anything else?
_No response_
### Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
Contributor guide
Research direction
Start in providers/http/src/airflow/providers/http/hooks/http.py at HttpHook._url_from_endpoint(), then check how HttpAsyncHook uses the shared helper. Reproduce the trailing-slash and leading-slash combination from the issue, and verify the resulting URL has exactly one separator while existing missing-slash behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100