fix(url): normalizeHost with ipv6 hostname#201
Open
chimurai wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
Been using
mockttpfor a long time inhttp-proxy-middlewareto mock the proxy target server.Great work on this library 🙏
Recently I updated
httpxy(dependency ofhttp-proxy-middleware) with improved IPv6 support: unjs/httpxy#136After updating
httpxysome of existing IPv6 tests started to fail: https://github.com/chimurai/http-proxy-middleware/blob/ffbf5bd59712704c9df178d5df61d96062a11b22/test/e2e/ipv6.spec.tsThese tests are using
mockttpwith as target server.I applied the fixes from this PR in this draft PR: chimurai/http-proxy-middleware#1234
Looks like it fixes the issue.
For full transparency, I used Copilot to help with analysis and creating this PR and the description below.
Summary
Fix IPv6 host serialization when reconstructing absolute request URLs from parsed destination data.
Mockttp already parses bracketed IPv6 Host headers correctly, but when rebuilding
host[:port]strings it was dropping the brackets. For requests like Host:[::1]:8000, that produced invalid absolute URLs such ashttp://::1:8000/api, which fail URL parsing and trigger a400before request handlers run.Changes
:80for HTTP and:443for HTTPS are still omitted[::1]:8000Example
Before:
Host:
[::1]:8000reconstructed URL:
http://::1:8000/apiURL parsing fails, request returns
400After:
Host:
[::1]:8000reconstructed URL:
http://[::1]:8000/apirequest is processed normally