swapURLHost replaces the host component of rawURL with newHost, preserving scheme, port (if already present in rawURL), path, and query unchanged.
(rawURL, newHost string)
| 162 | // swapURLHost replaces the host component of rawURL with newHost, preserving |
| 163 | // scheme, port (if already present in rawURL), path, and query unchanged. |
| 164 | func 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 | } |