Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Different Host behavior for setting host argument and getting Host header #1317

Closed
2 tasks done
WhiteApfel opened this issue Oct 19, 2021 · 3 comments 路 Fixed by #1322
Closed
2 tasks done

馃悰 Different Host behavior for setting host argument and getting Host header #1317

WhiteApfel opened this issue Oct 19, 2021 · 3 comments 路 Fixed by #1322

Comments

@WhiteApfel
Copy link
Contributor

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

When adding a host-based routes, host value can accept the port and does not process it in any way. But Host.matches() cuts off the port number (routing.py:432)

Expected behavior

When adding, cut off the port, or 褋onsider it when matching.

Actual behavior

import uvicorn as uvicorn
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.routing import Host, Router, Route

app = Starlette(routes=[
    Host('127.0.0.1:8889', app=Router(routes=[Route('/', lambda *a, **k: PlainTextResponse('Hello World'))])),
])

uvicorn.run(app, port=8889)

Breakpoint at routing.py:433
breakpoint variables

  • Starlette version: 0.16.0
WhiteApfel added a commit to WhiteApfel/starlette that referenced this issue Oct 19, 2021
WhiteApfel added a commit to WhiteApfel/starlette that referenced this issue Oct 19, 2021
@WhiteApfel
Copy link
Contributor Author

@aminalaee, maybe we should also cut off the port when matching host-based routes? As I understand it, the Host.host value is used to generate links via url_for, the port number may be useful there

@aminalaee
Copy link
Member

@WhiteApfel I agree. I think that can be useful in host-based routing,

@WhiteApfel
Copy link
Contributor Author

It might be cool to make the port handling principle similar to the subdomain principle

@aminalaee aminalaee linked a pull request Oct 27, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants