MCPcopy Create free account
hub / github.com/cli/cli / swapURLHost

Function swapURLHost

pkg/cmd/api/http.go:164–175  ·  view source on GitHub ↗

swapURLHost replaces the host component of rawURL with newHost, preserving scheme, port (if already present in rawURL), path, and query unchanged.

(rawURL, newHost string)

Source from the content-addressed store, hash-verified

162// swapURLHost replaces the host component of rawURL with newHost, preserving
163// scheme, port (if already present in rawURL), path, and query unchanged.
164func swapURLHost(rawURL, newHost string) string {
165 u, err := url.Parse(rawURL)
166 if err != nil {
167 // rawURL is always a well-formed URL built by ghinstance.GraphQLEndpoint
168 // or ghinstance.RESTPrefix, so this error is unreachable in practice. If it
169 // did occur, returning the input unchanged leaves the request pointed at the
170 // original host, which is safe (no host swap, but request still succeeds).
171 return rawURL
172 }
173 u.Host = newHost
174 return u.String()
175}

Callers 1

httpRequestFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected