Skip to content

Commit 4a58377

Browse files
committed
Check for ssl in listen directive to determine is an endpoint is using http ot https
1 parent fb0c657 commit 4a58377

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

sdk/config_helpers.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ import (
3939
const (
4040
plusAPIDirective = "api"
4141
stubStatusAPIDirective = "stub_status"
42-
apiFormat = "http://%s%s"
4342
predefinedAccessLogFormat = "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\""
4443
httpClientTimeout = 1 * time.Second
44+
httpPrefix = "http://"
45+
httpsPrefix = "https://"
4546
)
4647

4748
var readLock = sync.Mutex{}
@@ -698,6 +699,7 @@ func parseAddressesFromServerDirective(parent *crossplane.Directive) []string {
698699

699700
for _, dir := range parent.Block {
700701
hostname := "127.0.0.1"
702+
prefix := httpPrefix
701703

702704
switch dir.Directive {
703705
case "listen":
@@ -718,14 +720,22 @@ func parseAddressesFromServerDirective(parent *crossplane.Directive) []string {
718720
hostname = dir.Args[0]
719721
}
720722
}
721-
hosts = append(hosts, hostname)
723+
724+
if len(dir.Args) > 1 {
725+
secondArg := dir.Args[1]
726+
if secondArg == "ssl" {
727+
prefix = httpsPrefix
728+
}
729+
}
730+
731+
hosts = append(hosts, prefix+hostname)
722732
case "server_name":
723733
if dir.Args[0] == "_" {
724734
// default server
725735
continue
726736
}
727737
hostname = dir.Args[0]
728-
hosts = append(hosts, hostname)
738+
hosts = append(hosts, prefix+hostname)
729739
}
730740
}
731741

@@ -952,11 +962,11 @@ func getUrlsForLocationDirective(parent *crossplane.Directive, current *crosspla
952962
addresses := parseAddressesFromServerDirective(parent)
953963

954964
for _, address := range addresses {
955-
path := parsePathFromLocationDirective(current)
965+
pathFromLocationDirective := parsePathFromLocationDirective(current)
956966

957967
switch locChild.Directive {
958968
case locationDirectiveName:
959-
urls = append(urls, fmt.Sprintf(apiFormat, address, path))
969+
urls = append(urls, address+pathFromLocationDirective)
960970
}
961971
}
962972
}

test/integration/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/performance/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)