Skip to content

Commit 426e489

Browse files
committed
Fixes #411
1 parent 63ac63d commit 426e489

4 files changed

Lines changed: 99 additions & 36 deletions

File tree

issues/411/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```bash
2+
docker stack deploy -c stack.yml proxy
3+
4+
curl localhost/demoxxx/hello
5+
```

issues/411/stack.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: "3.2"
2+
3+
services:
4+
5+
proxy:
6+
image: vfarcic/docker-flow-proxy
7+
ports:
8+
- 80:80
9+
- 443:443
10+
networks:
11+
- default
12+
environment:
13+
- DFP_SERVICE_SERVICE_NAME=proxy_main
14+
- DFP_SERVICE_SERVICE_PATH=/demoxxx
15+
- DFP_SERVICE_REQ_PATH_SEARCH_REPLACE=/demoxxx,/demo
16+
- DFP_SERVICE_OUTBOUND_HOSTNAME=blog
17+
- DFP_SERVICE_PORT=8080
18+
19+
main:
20+
image: ${DOCKER_HUB_USER:-vfarcic}/go-demo-2:${TAG:-latest}
21+
environment:
22+
- DB=db
23+
networks:
24+
- default
25+
deploy:
26+
replicas: 3
27+
update_config:
28+
parallelism: 1
29+
delay: 10s
30+
labels:
31+
- com.df.notify=true
32+
- com.df.distribute=true
33+
- com.df.servicePath=/demo
34+
- com.df.port=8080
35+
36+
db:
37+
image: mongo
38+
networks:
39+
- default
40+
41+
networks:
42+
default:
43+
external: false

server/server.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,23 @@ func (m *serve) getServiceFromEnvVars(prefix string) (proxy.Service, error) {
269269
sd = append(
270270
sd,
271271
proxy.ServiceDest{
272-
HttpsOnly: httpsOnly,
273-
HttpsRedirectCode: httpsRedirectCode,
274-
OutboundHostname: globalOutboundHostname,
275-
Port: port,
276-
ReqMode: reqMode,
277-
ServiceDomain: domain,
278-
ServicePath: path,
279-
SrcPort: srcPort,
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,
280281
},
281282
)
282283
}
283284
for i := 1; i <= 10; i++ {
284285
port := os.Getenv(fmt.Sprintf("%s_PORT_%d", prefix, i))
285286
path := os.Getenv(fmt.Sprintf("%s_SERVICE_PATH_%d", prefix, i))
286287
reqMode := os.Getenv(fmt.Sprintf("%s_REQ_MODE_%d", prefix, i))
288+
reqPathSearchReplace := os.Getenv(fmt.Sprintf("%s_REQ_PATH_SEARCH_REPLACE_%d", prefix, i))
287289
httpsOnly, _ := strconv.ParseBool(os.Getenv(fmt.Sprintf("%s_HTTPS_ONLY_%d", prefix, i)))
288290
httpsRedirectCode := os.Getenv(fmt.Sprintf("%s_HTTPS_REDIRECT_CODE_%d", prefix, i))
289291
if len(reqMode) == 0 {
@@ -298,13 +300,14 @@ func (m *serve) getServiceFromEnvVars(prefix string) (proxy.Service, error) {
298300
sd = append(
299301
sd,
300302
proxy.ServiceDest{
301-
HttpsOnly: httpsOnly,
302-
HttpsRedirectCode: httpsRedirectCode,
303-
OutboundHostname: outboundHostname,
304-
Port: port,
305-
SrcPort: srcPort,
306-
ServicePath: strings.Split(path, ","),
307-
ReqMode: reqMode,
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,
308311
},
309312
)
310313
} else {

server/server_test.go

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,10 @@ func (s *ServerTestSuite) Test_GetServiceFromUrl_SetsServicePathToSlash_WhenDoma
662662

663663
func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
664664
service := proxy.Service{
665-
AclName: "my-AclName",
666-
AddReqHeader: []string{"add-header-1", "add-header-2"},
667-
AddResHeader: []string{"add-header-1", "add-header-2"},
668-
CompressionAlgo: "compressionAlgo",
669-
// CompressionType: "compressionType",
665+
AclName: "my-AclName",
666+
AddReqHeader: []string{"add-header-1", "add-header-2"},
667+
AddResHeader: []string{"add-header-1", "add-header-2"},
668+
CompressionAlgo: "compressionAlgo",
670669
ConnectionMode: "my-connection-mode",
671670
DelReqHeader: []string{"del-header-1", "del-header-2"},
672671
DelResHeader: []string{"del-header-1", "del-header-2"},
@@ -675,8 +674,6 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
675674
IsDefaultBackend: true,
676675
PathType: "my-PathType",
677676
RedirectWhenHttpProto: true,
678-
ReqPathReplace: "my-ReqPathReplace",
679-
ReqPathSearch: "my-ReqPathSearch",
680677
ServiceCert: "my-ServiceCert",
681678
ServiceDomainAlgo: "hdr_dom",
682679
ServiceName: "my-ServiceName",
@@ -689,14 +686,15 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
689686
TimeoutTunnel: "my-TimeoutTunnel",
690687
ServiceDest: []proxy.ServiceDest{
691688
{
692-
HttpsOnly: true,
693-
HttpsRedirectCode: "302",
694-
OutboundHostname: "my-OutboundHostname",
695-
Port: "1111",
696-
ServiceDomain: []string{"my-domain-1.com", "my-domain-2.com"},
697-
ServicePath: []string{"my-path-11", "my-path-12"},
698-
SrcPort: 1112,
699-
ReqMode: "my-ReqMode",
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",
700698
},
701699
},
702700
}
@@ -717,8 +715,7 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
717715
os.Setenv("DFP_SERVICE_PATH_TYPE", service.PathType)
718716
os.Setenv("DFP_SERVICE_REDIRECT_WHEN_HTTP_PROTO", strconv.FormatBool(service.RedirectWhenHttpProto))
719717
os.Setenv("DFP_SERVICE_REQ_MODE", service.ServiceDest[0].ReqMode)
720-
os.Setenv("DFP_SERVICE_REQ_PATH_REPLACE", service.ReqPathReplace)
721-
os.Setenv("DFP_SERVICE_REQ_PATH_SEARCH", service.ReqPathSearch)
718+
os.Setenv("DFP_SERVICE_REQ_PATH_SEARCH_REPLACE", service.ServiceDest[0].ReqPathSearchReplace)
722719
os.Setenv("DFP_SERVICE_SERVICE_CERT", service.ServiceCert)
723720
os.Setenv("DFP_SERVICE_SERVICE_DOMAIN", strings.Join(service.ServiceDest[0].ServiceDomain, ","))
724721
os.Setenv("DFP_SERVICE_SERVICE_DOMAIN_ALGO", service.ServiceDomainAlgo)
@@ -753,8 +750,7 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
753750
os.Unsetenv("DFP_SERVICE_PORT")
754751
os.Unsetenv("DFP_SERVICE_REDIRECT_WHEN_HTTP_PROTO")
755752
os.Unsetenv("DFP_SERVICE_REQ_MODE")
756-
os.Unsetenv("DFP_SERVICE_REQ_PATH_REPLACE")
757-
os.Unsetenv("DFP_SERVICE_REQ_PATH_SEARCH")
753+
os.Unsetenv("DFP_SERVICE_REQ_PATH_SEARCH_REPLACE")
758754
os.Unsetenv("DFP_SERVICE_SERVICE_CERT")
759755
os.Unsetenv("DFP_SERVICE_SERVICE_DOMAIN")
760756
os.Unsetenv("DFP_SERVICE_SERVICE_DOMAIN_ALGO")
@@ -812,17 +808,31 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServicesWithIndexed
812808
expected := proxy.Service{
813809
ServiceName: "my-ServiceName",
814810
ServiceDest: []proxy.ServiceDest{
815-
{Port: "1111", ServicePath: []string{"my-path-11", "my-path-12"}, SrcPort: 1112, HttpsOnly: true},
816-
{Port: "2221", ServicePath: []string{"my-path-21", "my-path-22"}, SrcPort: 2222, HttpsOnly: false, OutboundHostname: "my-outbound-domain.com"},
811+
{
812+
Port: "1111",
813+
ReqPathSearchReplace: "/this,/that",
814+
ServicePath: []string{"my-path-11", "my-path-12"},
815+
SrcPort: 1112,
816+
HttpsOnly: true,
817+
}, {
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",
824+
},
817825
},
818826
}
819827
os.Setenv("DFP_SERVICE_SERVICE_NAME", expected.ServiceName)
820828
os.Setenv("DFP_SERVICE_HTTPS_ONLY_1", "true")
821829
os.Setenv("DFP_SERVICE_PORT_1", expected.ServiceDest[0].Port)
830+
os.Setenv("DFP_SERVICE_REQ_PATH_SEARCH_REPLACE_1", expected.ServiceDest[0].ReqPathSearchReplace)
822831
os.Setenv("DFP_SERVICE_SERVICE_PATH_1", strings.Join(expected.ServiceDest[0].ServicePath, ","))
823832
os.Setenv("DFP_SERVICE_SRC_PORT_1", strconv.Itoa(expected.ServiceDest[0].SrcPort))
824833
os.Setenv("DFP_SERVICE_HTTPS_ONLY_2", "false")
825834
os.Setenv("DFP_SERVICE_PORT_2", expected.ServiceDest[1].Port)
835+
os.Setenv("DFP_SERVICE_REQ_PATH_SEARCH_REPLACE_2", expected.ServiceDest[1].ReqPathSearchReplace)
826836
os.Setenv("DFP_SERVICE_SERVICE_PATH_2", strings.Join(expected.ServiceDest[1].ServicePath, ","))
827837
os.Setenv("DFP_SERVICE_SRC_PORT_2", strconv.Itoa(expected.ServiceDest[1].SrcPort))
828838
os.Setenv("DFP_SERVICE_OUTBOUND_HOSTNAME_2", expected.ServiceDest[1].OutboundHostname)
@@ -831,10 +841,12 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServicesWithIndexed
831841
os.Unsetenv("DFP_SERVICE_SERVICE_NAME")
832842
os.Unsetenv("DFP_SERVICE_HTTPS_ONLY_1")
833843
os.Unsetenv("DFP_SERVICE_PORT_1")
844+
os.Unsetenv("DFP_SERVICE_REQ_PATH_SEARCH_REPLACE_1")
834845
os.Unsetenv("DFP_SERVICE_SERVICE_PATH_1")
835846
os.Unsetenv("DFP_SERVICE_SRC_PORT_1")
836847
os.Unsetenv("DFP_SERVICE_HTTPS_ONLY_2")
837848
os.Unsetenv("DFP_SERVICE_PORT_2")
849+
os.Unsetenv("DFP_SERVICE_REQ_PATH_SEARCH_REPLACE_2")
838850
os.Unsetenv("DFP_SERVICE_SERVICE_PATH_2")
839851
os.Unsetenv("DFP_SERVICE_SRC_PORT_2")
840852
os.Unsetenv("DFP_SERVICE_OUTBOUND_HOSTNAME_2")

0 commit comments

Comments
 (0)