Skip to content

Commit 1ddb79d

Browse files
tls-disable-redirect -> tls-redirect
Turning off the redirect previously involved setting its `disabled` value to `true`, which works fine but in retrospect feels a little like a double negative. Instead we can have a `tls-redirect` option that defaults to `true`, but can be set to `false` if we want to turn the behaviour off.
1 parent a35ec28 commit 1ddb79d

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

internal/cmd/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func newDeployCommand() *deployCommand {
3636
deployCommand.cmd.Flags().BoolVar(&deployCommand.tlsStaging, "tls-staging", false, "Use Let's Encrypt staging environment for certificate provisioning")
3737
deployCommand.cmd.Flags().StringVar(&deployCommand.args.ServiceOptions.TLSCertificatePath, "tls-certificate-path", "", "Configure custom TLS certificate path (PEM format)")
3838
deployCommand.cmd.Flags().StringVar(&deployCommand.args.ServiceOptions.TLSPrivateKeyPath, "tls-private-key-path", "", "Configure custom TLS private key path (PEM format)")
39-
deployCommand.cmd.Flags().BoolVar(&deployCommand.args.ServiceOptions.TLSDisableRedirect, "tls-disable-redirect", false, "Don't redirect HTTP traffic to HTTPS")
39+
deployCommand.cmd.Flags().BoolVar(&deployCommand.args.ServiceOptions.TLSRedirect, "tls-redirect", true, "Redirect HTTP traffic to HTTPS")
4040

4141
deployCommand.cmd.Flags().DurationVar(&deployCommand.args.DeployTimeout, "deploy-timeout", server.DefaultDeployTimeout, "Maximum time to wait for the new target to become healthy")
4242
deployCommand.cmd.Flags().DurationVar(&deployCommand.args.DrainTimeout, "drain-timeout", server.DefaultDrainTimeout, "Maximum time to allow existing connections to drain before removing old target")

internal/server/router_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func TestRouter_RestoreLastSavedState(t *testing.T) {
482482

483483
router := NewRouter(statePath)
484484
require.NoError(t, router.SetServiceTarget("default", defaultEmptyHosts, defaultPaths, first, defaultServiceOptions, defaultTargetOptions, DefaultDeployTimeout, DefaultDrainTimeout))
485-
require.NoError(t, router.SetServiceTarget("other1", []string{"other.example.com"}, defaultPaths, second, ServiceOptions{TLSEnabled: true}, defaultTargetOptions, DefaultDeployTimeout, DefaultDrainTimeout))
485+
require.NoError(t, router.SetServiceTarget("other1", []string{"other.example.com"}, defaultPaths, second, ServiceOptions{TLSEnabled: true, TLSRedirect: true}, defaultTargetOptions, DefaultDeployTimeout, DefaultDrainTimeout))
486486
require.NoError(t, router.SetServiceTarget("other2", []string{"other.example.com"}, []string{"/api"}, third, defaultServiceOptions, defaultTargetOptions, DefaultDeployTimeout, DefaultDrainTimeout))
487487

488488
statusCode, body := sendGETRequest(router, "http://something.example.com/")

internal/server/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type ServiceOptions struct {
6969
TLSEnabled bool `json:"tls_enabled"`
7070
TLSCertificatePath string `json:"tls_certificate_path"`
7171
TLSPrivateKeyPath string `json:"tls_private_key_path"`
72-
TLSDisableRedirect bool `json:"tls_disable_redirect"`
72+
TLSRedirect bool `json:"tls_redirect"`
7373
ACMEDirectory string `json:"acme_directory"`
7474
ACMECachePath string `json:"acme_cache_path"`
7575
ErrorPagePath string `json:"error_page_path"`
@@ -394,7 +394,7 @@ func (s *Service) serviceRequestWithTarget(w http.ResponseWriter, r *http.Reques
394394
}
395395

396396
func (s *Service) shouldRedirectToHTTPS(r *http.Request) bool {
397-
return s.options.TLSEnabled && !s.options.TLSDisableRedirect && r.TLS == nil
397+
return s.options.TLSEnabled && s.options.TLSRedirect && r.TLS == nil
398398
}
399399

400400
func (s *Service) handlePausedAndStoppedRequests(w http.ResponseWriter, r *http.Request) bool {

internal/server/service_map.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ func (m *ServiceMap) syncTLSOptionsFromRootDomain() {
160160
rootService := m.ServiceForHost(host)
161161
if rootService != nil {
162162
service.options.TLSEnabled = rootService.options.TLSEnabled
163-
service.options.TLSDisableRedirect = rootService.options.TLSDisableRedirect
163+
service.options.TLSRedirect = rootService.options.TLSRedirect
164164
} else {
165165
service.options.TLSEnabled = defaultServiceOptions.TLSEnabled
166-
service.options.TLSDisableRedirect = defaultServiceOptions.TLSDisableRedirect
166+
service.options.TLSRedirect = defaultServiceOptions.TLSRedirect
167167
}
168168
}
169169
}

internal/server/service_map_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func TestServiceMap_CheckAvailability(t *testing.T) {
7373

7474
func TestServiceMap_SyncingTLSSettingsFromRootPath(t *testing.T) {
7575
optionsWithTLS := ServiceOptions{
76-
TLSEnabled: true,
77-
TLSDisableRedirect: true,
76+
TLSEnabled: true,
77+
TLSRedirect: false,
7878
}
7979

8080
sm := NewServiceMap()
@@ -84,19 +84,19 @@ func TestServiceMap_SyncingTLSSettingsFromRootPath(t *testing.T) {
8484
sm.Set(normalizedService(&Service{name: "4", hosts: []string{"2.example.com"}, pathPrefixes: []string{"/api"}}))
8585

8686
assert.True(t, sm.Get("1").options.TLSEnabled)
87-
assert.True(t, sm.Get("1").options.TLSDisableRedirect)
87+
assert.False(t, sm.Get("1").options.TLSRedirect)
8888
assert.True(t, sm.Get("2").options.TLSEnabled)
89-
assert.True(t, sm.Get("2").options.TLSDisableRedirect)
89+
assert.False(t, sm.Get("2").options.TLSRedirect)
9090

9191
assert.False(t, sm.Get("3").options.TLSEnabled)
92-
assert.False(t, sm.Get("3").options.TLSDisableRedirect)
92+
assert.True(t, sm.Get("3").options.TLSRedirect)
9393
assert.False(t, sm.Get("4").options.TLSEnabled)
94-
assert.False(t, sm.Get("4").options.TLSDisableRedirect)
94+
assert.True(t, sm.Get("4").options.TLSRedirect)
9595

9696
sm.Remove("1")
9797

9898
assert.False(t, sm.Get("2").options.TLSEnabled)
99-
assert.False(t, sm.Get("2").options.TLSDisableRedirect)
99+
assert.True(t, sm.Get("2").options.TLSRedirect)
100100
}
101101

102102
func TestServiceMap_CheckHostAvailability_EmptyHostsFirst(t *testing.T) {

internal/server/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestService_ServeRequest(t *testing.T) {
2525
}
2626

2727
func TestService_RedirectToHTTPSWhenTLSRequired(t *testing.T) {
28-
service := testCreateService(t, []string{"example.com"}, ServiceOptions{TLSEnabled: true}, defaultTargetOptions)
28+
service := testCreateService(t, []string{"example.com"}, ServiceOptions{TLSEnabled: true, TLSRedirect: true}, defaultTargetOptions)
2929

3030
require.True(t, service.options.TLSEnabled)
3131

@@ -46,7 +46,7 @@ func TestService_RedirectToHTTPSWhenTLSRequired(t *testing.T) {
4646
func TestService_DontRedirectToHTTPSWhenTLSAndPlainHTTPAllowed(t *testing.T) {
4747
var forwardedProto string
4848

49-
service := testCreateServiceWithHandler(t, []string{"example.com"}, ServiceOptions{TLSEnabled: true, TLSDisableRedirect: true}, defaultTargetOptions,
49+
service := testCreateServiceWithHandler(t, []string{"example.com"}, ServiceOptions{TLSEnabled: true, TLSRedirect: false}, defaultTargetOptions,
5050
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5151
forwardedProto = r.Header.Get("X-Forwarded-Proto")
5252
}),

internal/server/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var (
1414
defaultHealthCheckConfig = HealthCheckConfig{Path: DefaultHealthCheckPath, Interval: DefaultHealthCheckInterval, Timeout: DefaultHealthCheckTimeout}
1515
defaultEmptyHosts = []string{}
1616
defaultPaths = []string{rootPath}
17-
defaultServiceOptions = ServiceOptions{}
17+
defaultServiceOptions = ServiceOptions{TLSRedirect: true}
1818
defaultTargetOptions = TargetOptions{HealthCheckConfig: defaultHealthCheckConfig, ResponseTimeout: DefaultTargetTimeout}
1919
)
2020

0 commit comments

Comments
 (0)