Skip to content

Conversation

@Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Mar 28, 2025

Closes #67

When req.headers.host is defined, the URL parsing breaks because there's no protocol.

@Skn0tt Skn0tt requested review from Copilot and pavelfeldman March 28, 2025 08:25
@Skn0tt Skn0tt self-assigned this Mar 28, 2025
Copy link

Copilot AI left a 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}`);

Copy link
Contributor

@mxschmitt mxschmitt left a 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}`);
Copy link
Contributor

@mxschmitt mxschmitt Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const url = new URL(req.url ?? '', `http://${req.headers.host}`);
const url = new URL(`http://${req.headers.host || 'localhost'}${req.url || ''}`;);

what about this?

Copy link
Member Author

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.

@Skn0tt
Copy link
Member Author

Skn0tt commented Mar 28, 2025

test would be lovely!

It's hard to test, because apparently our current client doesn't pass the Host header. Let's live without a test on this.

@Skn0tt Skn0tt merged commit edac6da into microsoft:main Mar 28, 2025
2 checks passed
pavelfeldman added a commit that referenced this pull request Mar 28, 2025
pavelfeldman added a commit that referenced this pull request Mar 28, 2025
Reverts #70

I was working on a bigger change and this conflicts.
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 this pull request may close these issues.

ERR_INVALID_URL when using Claude Desktop

2 participants