From 15b0e05ab54abab5f8f097161df4ef6eec248f9d Mon Sep 17 00:00:00 2001 From: Frank Olbricht Date: Mon, 17 Aug 2026 21:18:58 +0000 Subject: [PATCH 1/2] impl: fall back to CODER_HEADER_COMMAND when the header command setting is blank --- CHANGELOG.md | 4 ++++ .../gateway/CoderSettingsConfigurable.kt | 6 +++++- .../coder/gateway/settings/CoderSettings.kt | 10 ++++++--- .../messages/CoderGatewayBundle.properties | 3 ++- .../gateway/settings/CoderSettingsTest.kt | 21 +++++++++++++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3383697e..3ed26336 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## Unreleased +### Added + +- the header command falls back to the `CODER_HEADER_COMMAND` environment variable when the setting is blank, matching the Coder CLI and the VS Code extension + ## 2.23.1 - 2026-01-21 ### Changed diff --git a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt index 76096e98..76eac4fa 100644 --- a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt +++ b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt @@ -2,6 +2,7 @@ package com.coder.gateway import com.coder.gateway.services.CoderSettingsService import com.coder.gateway.services.CoderSettingsStateService +import com.coder.gateway.settings.CODER_HEADER_COMMAND import com.coder.gateway.settings.CODER_SSH_CONFIG_OPTIONS import com.coder.gateway.util.canCreateDirectory import com.intellij.openapi.components.service @@ -89,7 +90,10 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") { textField().resizableColumn().align(AlignX.FILL) .bindText(state::headerCommand) .comment( - CoderGatewayBundle.message("gateway.connector.settings.header-command.comment"), + CoderGatewayBundle.message( + "gateway.connector.settings.header-command.comment", + CODER_HEADER_COMMAND, + ), ) }.layout(RowLayout.PARENT_GRID) row(CoderGatewayBundle.message("gateway.connector.settings.tls-cert-path.title")) { diff --git a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt index a189df82..74b1d4db 100644 --- a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt +++ b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt @@ -14,6 +14,7 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +const val CODER_HEADER_COMMAND = "CODER_HEADER_COMMAND" const val CODER_SSH_CONFIG_OPTIONS = "CODER_SSH_CONFIG_OPTIONS" const val CODER_URL = "CODER_URL" @@ -77,7 +78,8 @@ open class CoderSettingsState( // An external command that outputs additional HTTP headers added to all // requests. The command must output each header as `key=value` on its own // line. The following environment variables will be available to the - // process: CODER_URL. + // process: CODER_URL. If blank, the CODER_HEADER_COMMAND environment + // variable is used, if set. open var headerCommand: String = "", // Optionally set this to the path of a certificate to use for TLS // connections. The certificate should be in X.509 PEM format. @@ -194,10 +196,12 @@ open class CoderSettings( val defaultSignatureNameByOsAndArch: String get() = getCoderSignatureForOS(getOS(), getArch()) /** - * A command to run to set headers for API calls. + * A command to run to set headers for API calls. Falls back to the + * CODER_HEADER_COMMAND environment variable (the same variable the Coder + * CLI reads) when the setting is blank. */ val headerCommand: String - get() = state.headerCommand + get() = state.headerCommand.ifBlank { env.get(CODER_HEADER_COMMAND) } /** * Whether to disable automatically starting a workspace when connecting. diff --git a/src/main/resources/messages/CoderGatewayBundle.properties b/src/main/resources/messages/CoderGatewayBundle.properties index 00afdbfa..fbd9ce44 100644 --- a/src/main/resources/messages/CoderGatewayBundle.properties +++ b/src/main/resources/messages/CoderGatewayBundle.properties @@ -83,7 +83,8 @@ gateway.connector.settings.header-command.title=Header command gateway.connector.settings.header-command.comment=An external command that \ outputs additional HTTP headers added to all requests. The command must \ output each header as `key=value` on its own line. The following \ - environment variables will be available to the process: CODER_URL. + environment variables will be available to the process: CODER_URL. If left \ + blank the environment variable {0} will be used, if set. gateway.connector.settings.tls-cert-path.title=Cert path gateway.connector.settings.tls-cert-path.comment=Optionally set this to \ the path of a certificate to use for TLS connections. The certificate \ diff --git a/src/test/kotlin/com/coder/gateway/settings/CoderSettingsTest.kt b/src/test/kotlin/com/coder/gateway/settings/CoderSettingsTest.kt index 71447db5..7d877a17 100644 --- a/src/test/kotlin/com/coder/gateway/settings/CoderSettingsTest.kt +++ b/src/test/kotlin/com/coder/gateway/settings/CoderSettingsTest.kt @@ -243,6 +243,27 @@ internal class CoderSettingsTest { assertEquals(Pair("http://test.gateway.coder.com$expected", null), got) } + @Test + fun testHeaderCommand() { + var settings = CoderSettings(CoderSettingsState(headerCommand = "header command from state")) + assertEquals("header command from state", settings.headerCommand) + + settings = + CoderSettings( + CoderSettingsState(), + env = Environment(mapOf(CODER_HEADER_COMMAND to "header command from env")), + ) + assertEquals("header command from env", settings.headerCommand) + + // State has precedence. + settings = + CoderSettings( + CoderSettingsState(headerCommand = "header command from state"), + env = Environment(mapOf(CODER_HEADER_COMMAND to "header command from env")), + ) + assertEquals("header command from state", settings.headerCommand) + } + @Test fun testSSHConfigOptions() { var settings = CoderSettings(CoderSettingsState(sshConfigOptions = "ssh config options from state")) From a66796cf4ed00ce8c0659324e6bf212b0f45bb8a Mon Sep 17 00:00:00 2001 From: Frank Olbricht Date: Tue, 18 Aug 2026 14:13:58 +0000 Subject: [PATCH 2/2] docs: drop CODER_URL mention and clarify the header command fallback wording --- src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt | 5 ++--- src/main/resources/messages/CoderGatewayBundle.properties | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt index 74b1d4db..3917b8a7 100644 --- a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt +++ b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt @@ -77,9 +77,8 @@ open class CoderSettingsState( // An external command that outputs additional HTTP headers added to all // requests. The command must output each header as `key=value` on its own - // line. The following environment variables will be available to the - // process: CODER_URL. If blank, the CODER_HEADER_COMMAND environment - // variable is used, if set. + // line. When this setting is blank, the CODER_HEADER_COMMAND environment + // variable is used instead, if set. open var headerCommand: String = "", // Optionally set this to the path of a certificate to use for TLS // connections. The certificate should be in X.509 PEM format. diff --git a/src/main/resources/messages/CoderGatewayBundle.properties b/src/main/resources/messages/CoderGatewayBundle.properties index fbd9ce44..5c34379d 100644 --- a/src/main/resources/messages/CoderGatewayBundle.properties +++ b/src/main/resources/messages/CoderGatewayBundle.properties @@ -82,9 +82,8 @@ gateway.connector.settings.fallback-on-coder-for-signatures.comment=Verify binar gateway.connector.settings.header-command.title=Header command gateway.connector.settings.header-command.comment=An external command that \ outputs additional HTTP headers added to all requests. The command must \ - output each header as `key=value` on its own line. The following \ - environment variables will be available to the process: CODER_URL. If left \ - blank the environment variable {0} will be used, if set. + output each header as `key=value` on its own line. When this setting is \ + left blank, the environment variable {0} is used instead, if set. gateway.connector.settings.tls-cert-path.title=Cert path gateway.connector.settings.tls-cert-path.comment=Optionally set this to \ the path of a certificate to use for TLS connections. The certificate \