-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: tired URL parsing bug #70
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a URL parsing bug by ensuring that the URL constructor receives a proper base URL when req.headers.host is defined.
- Fixes URL parsing by providing an explicit protocol via "http://".
- Removes redundant host concatenation logic.
Comments suppressed due to low confidence (1)
src/program.ts:57
- Consider providing a fallback or additional validation for req.headers.host to avoid constructing a URL with an undefined host value, which may lead to runtime errors.
const url = new URL(req.url ?? '', `http://${req.headers.host}`);
mxschmitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test would be lovely!
| if (options.port) { | ||
| const sessions = new Map<string, SSEServerTransport>(); | ||
| const httpServer = http.createServer(async (req, res) => { | ||
| const url = new URL(req.url ?? '', `http://${req.headers.host}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const url = new URL(req.url ?? '', `http://${req.headers.host}`); | |
| const url = new URL(`http://${req.headers.host || 'localhost'}${req.url || ''}`;); |
what about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be exactly the same, because req.url is always absolute.
It's hard to test, because apparently our current client doesn't pass the |
This reverts commit edac6da.
Reverts #70 I was working on a bigger change and this conflicts.
Closes #67
When
req.headers.hostis defined, the URL parsing breaks because there's no protocol.