Repository navigation
fix(fetch): preserve localhost hostname without rewriting to 127.0.0.1 (#13339) - #13387
Open
patrickswedish wants to merge 1 commit into
Open
patrickswedish wants to merge 1 commit into
patrickswedish wants to merge 1 commit into
Conversation
continuedev#13339) fetchwithRequestOptions unconditionally rewrote url.host and url.hostname from localhost to 127.0.0.1. In environments involving WSL2, IPv6 loopback (e.g. servers bound to [::1]), containers, or custom virtual host routing, rewriting localhost to 127.0.0.1 causes requests to fail with ECONNREFUSED. This commit: - Preserves the caller-configured localhost hostname in packages/fetch/src/fetch.ts without mutating it to 127.0.0.1. - Clones input URL instances to prevent in-place mutation of caller objects. - Aligns LlamaCpp default apiBase to http://localhost:8080/ consistent with all other local providers. - Adds an end-to-end test verifying localhost is preserved on outgoing requests. Closes continuedev#13339 Signed-off-by: Patrick Ribbsaeter <patrickswedish@gmail.com>
This branch has not been deployed
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.
Summary
Resolves #13339
In
fetchwithRequestOptions(packages/fetch/src/fetch.ts),url.hostandurl.hostnamewere unconditionally rewritten from"localhost"to"127.0.0.1". In environments with WSL2, IPv6 loopback (e.g., servers bound strictly to[::1]:8080), containerized networks, or virtual host routing, rewritinglocalhostto127.0.0.1causes connection attempts to fail withconnect ECONNREFUSED 127.0.0.1:8080.Furthermore, if the caller passed a
URLinstance intofetchwithRequestOptions,url.hostname = "127.0.0.1"mutated the caller'sURLin place.Changes
localhost: Removed unconditional mutations ofurl.hostandurl.hostnameto"127.0.0.1"inpackages/fetch/src/fetch.ts, allowing the runtime/OS resolver to handle loopback address resolution cleanly.URLobjects vianew URL(url_.toString())if passed as an instance.apiBase: UpdatedLlamaCppdefaultapiBaseincore/llm/llms/LlamaCpp.tsfrom"http://127.0.0.1:8080/"to"http://localhost:8080/", matching all other local providers (Ollama,LMStudio,HuggingFaceTEI, etc.).packages/fetch/src/fetch.e2e.test.tsverifying thatlocalhostis preserved on outgoing requests and callerURLinstances are not mutated.Test Plan
packages/fetch: verifiedshould preserve localhost hostname without rewriting to 127.0.0.1 (#13339)passes cleanly.Hostheader retainslocalhost:<PORT>.packages/fetch.