Conversation
Copilot
AI
changed the title
[WIP] Fix 'http:' not supported error in self-hosted GitLab
fix: use agent function to support HTTP/HTTPS protocol switching in self-hosted GitLab
Mar 17, 2026
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…hing When self-hosted GitLab instances redirect between HTTP and HTTPS (e.g., when external_url differs from the actual internal protocol), node-fetch needs an agent function instead of a static agent to select the correct HTTP or HTTPS agent based on each request's URL protocol. - Add getAgentFunctionForUrl() to GitLabClientPool that returns a (parsedURL: URL) => Agent function for use with node-fetch - Extract shared logic into private getOrCreateAgentsForUrl() method - Update getFetchConfig() to use the agent function Fixes: Protocol "http:" not supported. Expected "https:" error Co-authored-by: zereight <42544600+zereight@users.noreply.github.com>
55e75c2 to
af41324
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the GitLab HTTP client configuration to support protocol switching (HTTP ↔ HTTPS) during redirects and when following http:// links returned by some self-hosted GitLab instances, avoiding node-fetch agent/protocol mismatch errors.
Changes:
- Introduces
getAgentFunctionForUrl()in the GitLab client pool to dynamically select an HTTP vs HTTPS agent per request URL. - Refactors shared agent-pair lookup/creation into a private
getOrCreateAgentsForUrl()helper. - Switches
index.tsfetch configuration to use the new agent function instead of a static agent instance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
gitlab-client-pool.ts |
Adds an agent-selection function (and shared agent-pair retrieval) to handle protocol changes across redirects/URLs. |
index.ts |
Uses the agent function in getFetchConfig() so node-fetch can pick the correct agent per request/redirect. |
Comments suppressed due to low confidence (1)
gitlab-client-pool.ts:112
- The new protocol-switching behavior (agent function selecting HTTP vs HTTPS agents) is a regression-prone fix, but there’s no automated test exercising it. Consider adding a small unit test for
getAgentFunctionForUrl()that asserts the returned function selectshttpAgentforhttp:URLs andhttpsAgentforhttps:URLs (and ideally covers the original failure mode via a simulated redirect/protocol switch).
private createAgentsForUrl(apiUrl: string): ClientAgents {
const { httpProxy, httpsProxy, noProxy, rejectUnauthorized, caCertPath } = this.options;
const url = new URL(apiUrl);
let sslOptions: { rejectUnauthorized?: boolean; ca?: Buffer } = {};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Self-hosted GitLab instances behind HTTPS proxies often return
http://URLs in API responses or issue HTTP redirects internally.node-fetchwas configured with a static agent (e.g., HTTPS-only), so any protocol switch during redirects would fail withProtocol "http:" not supported. Expected "https:".Changes
gitlab-client-pool.ts: AddgetAgentFunctionForUrl()returning a(parsedURL: URL) => Agentfunction that dynamically selects HTTP or HTTPS agent per-request. Extract shared agent lookup into privategetOrCreateAgentsForUrl().index.ts: SwitchgetFetchConfig()from static agent to agent function.node-fetchsupports an agent function that is called per-request, including on redirects:Original prompt
This section details on the original issue you should resolve
<issue_title>Self-hosted GitLab with HTTP: "Protocol 'http:' not supported" error</issue_title>
<issue_description>## Description
When using a self-hosted GitLab instance that returns
http://URLs in API responses (e.g.selflinks, resource URLs), some operations fail with:MCP error -32603: Protocol "http:" not supported. Expected "https:"
This happens even when
GITLAB_API_URLis set tohttps://. The issue is that GitLab API responses may contain internal links usinghttp://(common in self-hosted setups whereexternal_urldiffers from the actual protocol), and the MCP server's HTTP client rejects them.Steps to reproduce
http://in API response bodiesGITLAB_API_URL=https://gitlab.example.com/api/v4get_projectExpected behavior
The server should handle
http://URLs from API responses, or at minimum use the protocol fromGITLAB_API_URLwhen constructing follow-up requests.Actual behavior
Error: MCP error -32603: Protocol "http:" not supported. Expected "https:"
Workaround ...
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.