Skip to content

Commit f4a0ea5

Browse files
committed
Fixes #411
1 parent 426e489 commit f4a0ea5

2 files changed

Lines changed: 61 additions & 45 deletions

File tree

server/server.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,26 @@ func (m *serve) getServiceFromEnvVars(prefix string) (proxy.Service, error) {
264264
httpsOnly, _ := strconv.ParseBool(os.Getenv(prefix + "_HTTPS_ONLY"))
265265
httpsRedirectCode := os.Getenv(prefix + "_HTTPS_REDIRECT_CODE")
266266
globalOutboundHostname := os.Getenv(prefix + "_OUTBOUND_HOSTNAME")
267+
reqPathSearchReplace := os.Getenv(prefix + "_REQ_PATH_SEARCH_REPLACE")
268+
reqPathSearchReplaceFormatted := []string{}
269+
if len(reqPathSearchReplace) > 0 {
270+
reqPathSearchReplaceFormatted = strings.Split(reqPathSearchReplace, ":")
271+
}
267272

268273
if len(path) > 0 || len(port) > 0 {
269274
sd = append(
270275
sd,
271276
proxy.ServiceDest{
272-
HttpsOnly: httpsOnly,
273-
HttpsRedirectCode: httpsRedirectCode,
274-
OutboundHostname: globalOutboundHostname,
275-
Port: port,
276-
ReqMode: reqMode,
277-
ReqPathSearchReplace: os.Getenv(prefix + "_REQ_PATH_SEARCH_REPLACE"),
278-
ServiceDomain: domain,
279-
ServicePath: path,
280-
SrcPort: srcPort,
277+
HttpsOnly: httpsOnly,
278+
HttpsRedirectCode: httpsRedirectCode,
279+
OutboundHostname: globalOutboundHostname,
280+
Port: port,
281+
ReqMode: reqMode,
282+
ReqPathSearchReplace: reqPathSearchReplace,
283+
ReqPathSearchReplaceFormatted: reqPathSearchReplaceFormatted,
284+
ServiceDomain: domain,
285+
ServicePath: path,
286+
SrcPort: srcPort,
281287
},
282288
)
283289
}
@@ -286,6 +292,10 @@ func (m *serve) getServiceFromEnvVars(prefix string) (proxy.Service, error) {
286292
path := os.Getenv(fmt.Sprintf("%s_SERVICE_PATH_%d", prefix, i))
287293
reqMode := os.Getenv(fmt.Sprintf("%s_REQ_MODE_%d", prefix, i))
288294
reqPathSearchReplace := os.Getenv(fmt.Sprintf("%s_REQ_PATH_SEARCH_REPLACE_%d", prefix, i))
295+
reqPathSearchReplaceFormatted := []string{}
296+
if len(reqPathSearchReplace) > 0 {
297+
reqPathSearchReplaceFormatted = strings.Split(reqPathSearchReplace, ":")
298+
}
289299
httpsOnly, _ := strconv.ParseBool(os.Getenv(fmt.Sprintf("%s_HTTPS_ONLY_%d", prefix, i)))
290300
httpsRedirectCode := os.Getenv(fmt.Sprintf("%s_HTTPS_REDIRECT_CODE_%d", prefix, i))
291301
if len(reqMode) == 0 {
@@ -300,14 +310,15 @@ func (m *serve) getServiceFromEnvVars(prefix string) (proxy.Service, error) {
300310
sd = append(
301311
sd,
302312
proxy.ServiceDest{
303-
HttpsOnly: httpsOnly,
304-
HttpsRedirectCode: httpsRedirectCode,
305-
OutboundHostname: outboundHostname,
306-
Port: port,
307-
ReqPathSearchReplace: reqPathSearchReplace,
308-
SrcPort: srcPort,
309-
ServicePath: strings.Split(path, ","),
310-
ReqMode: reqMode,
313+
HttpsOnly: httpsOnly,
314+
HttpsRedirectCode: httpsRedirectCode,
315+
OutboundHostname: outboundHostname,
316+
Port: port,
317+
ReqPathSearchReplace: reqPathSearchReplace,
318+
ReqPathSearchReplaceFormatted: reqPathSearchReplaceFormatted,
319+
SrcPort: srcPort,
320+
ServicePath: strings.Split(path, ","),
321+
ReqMode: reqMode,
311322
},
312323
)
313324
} else {

server/server_test.go

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,16 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
686686
TimeoutTunnel: "my-TimeoutTunnel",
687687
ServiceDest: []proxy.ServiceDest{
688688
{
689-
HttpsOnly: true,
690-
HttpsRedirectCode: "302",
691-
OutboundHostname: "my-OutboundHostname",
692-
Port: "1111",
693-
ReqPathSearchReplace: "/something,/else",
694-
ServiceDomain: []string{"my-domain-1.com", "my-domain-2.com"},
695-
ServicePath: []string{"my-path-11", "my-path-12"},
696-
SrcPort: 1112,
697-
ReqMode: "my-ReqMode",
689+
HttpsOnly: true,
690+
HttpsRedirectCode: "302",
691+
OutboundHostname: "my-OutboundHostname",
692+
Port: "1111",
693+
ReqPathSearchReplace: "/something,/else:/this,/that",
694+
ReqPathSearchReplaceFormatted: []string{"/something,/else", "/this,/that"},
695+
ServiceDomain: []string{"my-domain-1.com", "my-domain-2.com"},
696+
ServicePath: []string{"my-path-11", "my-path-12"},
697+
SrcPort: 1112,
698+
ReqMode: "my-ReqMode",
698699
},
699700
},
700701
}
@@ -779,9 +780,10 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_SetsServiceDomainAlgoToHdr
779780
ServiceName: "my-ServiceName",
780781
ServiceDest: []proxy.ServiceDest{
781782
{
782-
ServiceDomain: []string{"my-domain-1.com", "my-domain-2.com"},
783-
ServicePath: []string{"my-path-11", "my-path-12"},
784-
ReqMode: "http",
783+
ReqMode: "http",
784+
ReqPathSearchReplaceFormatted: []string{},
785+
ServiceDomain: []string{"my-domain-1.com", "my-domain-2.com"},
786+
ServicePath: []string{"my-path-11", "my-path-12"},
785787
},
786788
},
787789
ServiceDomainAlgo: "hdr_dom(host)",
@@ -809,18 +811,20 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServicesWithIndexed
809811
ServiceName: "my-ServiceName",
810812
ServiceDest: []proxy.ServiceDest{
811813
{
812-
Port: "1111",
813-
ReqPathSearchReplace: "/this,/that",
814-
ServicePath: []string{"my-path-11", "my-path-12"},
815-
SrcPort: 1112,
816-
HttpsOnly: true,
814+
Port: "1111",
815+
ReqPathSearchReplace: "/this,/that",
816+
ReqPathSearchReplaceFormatted: []string{"/this,/that"},
817+
ServicePath: []string{"my-path-11", "my-path-12"},
818+
SrcPort: 1112,
819+
HttpsOnly: true,
817820
}, {
818-
Port: "2221",
819-
ReqPathSearchReplace: "/something,/else",
820-
ServicePath: []string{"my-path-21", "my-path-22"},
821-
SrcPort: 2222,
822-
HttpsOnly: false,
823-
OutboundHostname: "my-outbound-domain.com",
821+
Port: "2221",
822+
ReqPathSearchReplace: "/something,/else",
823+
ReqPathSearchReplaceFormatted: []string{"/something,/else"},
824+
ServicePath: []string{"my-path-21", "my-path-22"},
825+
SrcPort: 2222,
826+
HttpsOnly: false,
827+
OutboundHostname: "my-outbound-domain.com",
824828
},
825829
},
826830
}
@@ -872,11 +876,12 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsMultipleServices()
872876
ServiceName: "my-ServiceName",
873877
ServiceDest: []proxy.ServiceDest{
874878
{
875-
Port: "1111",
876-
ServiceDomain: []string{},
877-
ServicePath: []string{"my-path-11", "my-path-12"},
878-
SrcPort: 1112,
879-
ReqMode: "http",
879+
Port: "1111",
880+
ReqPathSearchReplaceFormatted: []string{},
881+
ServiceDomain: []string{},
882+
ServicePath: []string{"my-path-11", "my-path-12"},
883+
SrcPort: 1112,
884+
ReqMode: "http",
880885
},
881886
},
882887
}

0 commit comments

Comments
 (0)