Skip to content

Commit 8e2356b

Browse files
committed
2 parents fd2ac85 + 7cdf978 commit 8e2356b

3 files changed

Lines changed: 33 additions & 20 deletions

File tree

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The following query parameters can be used only when `reqMode` is set to `http`
5454
|outboundHostname|The hostname where the service is running, for instance on a separate swarm. If specified, the proxy will dispatch requests to that domain. The parameter can be prefixed with an index thus allowing definition of multiple destinations for a single service (e.g. `outboundHostname.1`, `outboundHostname.2`, and so on).<br>**Example:** `ecme.com`|
5555
|pathType |The ACL derivative. Defaults to *path_beg*. See [HAProxy path](https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#7.3.6-path) for more info.<br>**Example:** `path_beg`|
5656
|redirectFromDomain|If a request is sent to one of the domains in this list, it will be redirected to one of the values of the `serviceDomain`. Multiple domains can be separated with comma (e.g. `acme.com,something.acme.com`). The parameter can be prefixed with an index thus allowing definition of multiple destinations for a single service.<br>**Example:** `acme.com,something.acme.com`|
57-
|redirectWhenHttpProto|**This parameter is temporarily disabled until the problems around it are solved**. Whether to redirect to https when X-Forwarded-Proto is set and the request is made over an HTTP port.<br>**Example:** `true`<br>**Default Value:** `false`|
57+
|redirectWhenHttpProto|Whether to redirect to https when X-Forwarded-Proto is set and the request is made over an HTTP port.<br>**Example:** `true`<br>**Default Value:** `false`|
5858
|serviceCert |Content of the PEM-encoded certificate to be used by the proxy when serving traffic over SSL.|
5959
|serviceDomain |The domain of the service. If set, the proxy will allow access only to requests coming to that domain. Multiple domains can be separated with comma (e.g. `acme.com,something.else.com`). The parameter can be prefixed with an index thus allowing definition of multiple destinations for a single service (e.g. `serviceDomain.1`, `serviceDomain.2`, and so on). Asterisk sign can be placed to beginning of value and in this case **serviceDomainAlgo** parameter will be **replaced** to `hdr_end(host)`. This parameter is **mandatory** if `servicePath` is not specified.<br>**Example:** `ecme.com`|
6060
|serviceDomainAlgo|Algorithm that should be applied to domain ACLs. Any ACL works only with one flag: `-i : ignore case during matching of all subsequent patterns`. If not set, the value of the environment variable `SERVICE_DOMAIN_ALGO` will be used instead. If defaults to `hdr_beg(host)`<br>**Examples:**<br>`hdr(host)`: matches only if domain is the same as `serviceDomain`<br>`hdr_dom(host)`: matches the specified `serviceDomain` and any subdomain (a string either isolated or delimited by dots). **Example:** if `hdr_dom(host)` contains `www.ecme.com` and `serviceDomain` equals `ecme.com` the rule will be passed.<br>`req.ssl_sni`: matches Server Name TLS extension|

proxy/util.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,41 @@ import (
1818
var haProxyCmd = "haproxy"
1919

2020
var cmdRunHa = func(args []string) error {
21-
var stdoutBuf, stderrBuf bytes.Buffer
22-
cmd := exec.Command(haProxyCmd, args...)
23-
cmd.Stdout = &stdoutBuf
24-
cmd.Stderr = &stderrBuf
25-
err := cmd.Run()
21+
var stdoutBuf, stderrBuf bytes.Buffer
22+
cmd := exec.Command(haProxyCmd, args...)
2623

27-
stdOut, stdErr := stdoutBuf.String(), stderrBuf.String()
24+
stdoutIn, _ := cmd.StdoutPipe()
25+
stderrIn, _ := cmd.StderrPipe()
2826

29-
if strings.Contains(stdOut, "could not resolve address") || stdErr != "" || err != nil {
30-
return fmt.Errorf("out:\n%s\nerr:\n%s\n", stdOut, stdErr)
31-
}
27+
stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
28+
stderr := io.MultiWriter(os.Stderr, &stderrBuf)
29+
cmd.Start()
30+
31+
go func() {
32+
io.Copy(stdout, stdoutIn)
33+
}()
34+
35+
go func() {
36+
io.Copy(stderr, stderrIn)
37+
}()
38+
39+
err := cmd.Wait()
40+
41+
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
42+
combinedOut := fmt.Sprintf("\nstdout:\n%s\nstderr:\n%s\n", outStr, errStr)
3243

33-
return nil
44+
if exitError, ok := err.(*exec.ExitError); ok {
45+
waitStatus := exitError.Sys().(syscall.WaitStatus)
46+
fmt.Printf("Exit Status: %s\n", []byte(fmt.Sprintf("%d", waitStatus.ExitStatus())))
47+
return fmt.Errorf(combinedOut)
48+
}
49+
50+
if errStr != "" {
51+
fmt.Println("The configuration file is valid, but there still may be a misconfiguration",
52+
"somewhere that will give unexpected results, please verify:", combinedOut)
53+
}
54+
55+
return nil
3456
}
3557

3658
var cmdValidateHa = func(args []string) error {

proxy/util_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ func (s *UtilTestSuite) Test_HaProxyCmd_DoesNotReturnErrorWhenStdErrIsEmpty() {
2929
s.NoError(err)
3030
}
3131

32-
func (s *UtilTestSuite) Test_HaProxyCmd_ReturnsError_WhenOutputContainsCouldNotResolveAddress() {
33-
haProxyCmdOrig := haProxyCmd
34-
defer func() { haProxyCmd = haProxyCmdOrig }()
35-
haProxyCmd = "echo"
36-
err := cmdRunHa([]string{"'I really could not resolve address and something else'"})
37-
38-
s.Error(err)
39-
}
40-
4132
func (s *UtilTestSuite) Test_HaProxyCmd_ReturnsError_WhenStdErrIsNotEmpty() {
4233
haProxyCmdOrig := haProxyCmd
4334
defer func() { haProxyCmd = haProxyCmdOrig }()

0 commit comments

Comments
 (0)