π OpenHands: AI-Driven Development
fix: preserve target protocol in buildHttpBaseUrl (#1297)
Calvin Smithd823e0137dd6
diff --git a/__tests__/api/bash-service.test.ts b/__tests__/api/bash-service.test.tsindex 98a89ee827..5bd86f294a 100644--- a/__tests__/api/bash-service.test.ts+++ b/__tests__/api/bash-service.test.ts@@ -152,7 +152,7 @@ describe("BashService.listOutputs β cloud backend", () => {const proxyCall = vi.mocked(callCloudProxy).mock.calls[0][0];expect(proxyCall.method).toBe("GET");expect(proxyCall.path).toMatch(/^\/api\/bash\/bash_events\/search\?/);- expect(proxyCall.hostOverride).toBe("http://runtime.example.com");+ expect(proxyCall.hostOverride).toBe("https://runtime.example.com");expect(proxyCall.authMode).toBe("session-api-key");expect(proxyCall.sessionApiKey).toBe(SESSION_KEY);diff --git a/__tests__/api/runtime-service/agent-server-runtime-service.test.ts b/__tests__/api/runtime-service/agent-server-runtime-service.test.tsindex 8fd0941fef..e37bdb3b65 100644--- a/__tests__/api/runtime-service/agent-server-runtime-service.test.ts+++ b/__tests__/api/runtime-service/agent-server-runtime-service.test.ts@@ -141,8 +141,7 @@ describe("AgentServerRuntimeService.executeCommand", () => {const proxyCall = vi.mocked(callCloudProxy).mock.calls[0][0];expect(proxyCall.method).toBe("POST");expect(proxyCall.path).toBe("/api/bash/execute_bash_command");- // hostOverride resolves to http:// because JSDOM's window.location.protocol is http:- expect(proxyCall.hostOverride).toBe("http://runtime.example.com");+ expect(proxyCall.hostOverride).toBe("https://runtime.example.com");expect(proxyCall.body).toEqual({command: "find . -type f",cwd: "/workspace/project",@@ -271,7 +270,7 @@ describe("AgentServerRuntimeService.downloadFile", () => {expect(proxyCall.path).toBe("/api/file/download?path=%2Fworkspace%2Fproject%2Fsrc%2Fmain.ts",);- expect(proxyCall.hostOverride).toBe("http://runtime.example.com");+ expect(proxyCall.hostOverride).toBe("https://runtime.example.com");expect(proxyCall.authMode).toBe("session-api-key");expect(proxyCall.sessionApiKey).toBe(SESSION_KEY);expect(proxyCall.responseType).toBe("blob");diff --git a/src/utils/websocket-url.ts b/src/utils/websocket-url.tsindex 289ce09d90..38d11362ba 100644--- a/src/utils/websocket-url.ts+++ b/src/utils/websocket-url.ts@@ -57,7 +57,10 @@ export function buildHttpBaseUrl(): string {const baseHost = extractBaseHost(conversationUrl);const pathPrefix = extractPathPrefix(conversationUrl);- const protocol = window.location.protocol === "https:" ? "https:" : "http:";+ const pageIsSecure = window.location.protocol === "https:";+ const targetIsSecure =+ getConversationUrlProtocol(conversationUrl) === "https:";+ const protocol = pageIsSecure || targetIsSecure ? "https:" : "http:";return `${protocol}//${baseHost}${pathPrefix}`;}