Skip to content

Commit 443d921

Browse files
STRIP_PATH applies before the health check
STRIP_PATH worked great for fixing my AWS application load balancer, but it didn't help with my health checks. Prior to this commit, the health check URL was not subject to STRIP_PATH. Now it is. In addition, STRIP_PATH now works as you would expect it to, given the documentation: it strips the path *prefix*. Previously, this would just remove the STRIP_PATH text *anywhere* that it appeared in the path.
1 parent 10779fd commit 443d921

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ func main() {
7272
}
7373
})
7474

75-
if c.healthCheckPath != "" {
76-
http.HandleFunc(c.healthCheckPath, func(w http.ResponseWriter, r *http.Request) {
77-
w.WriteHeader(http.StatusOK)
78-
})
79-
}
80-
8175
// Listen & Serve
8276
log.Printf("[service] listening on port %s", c.port)
8377
if (len(c.sslCert) > 0) && (len(c.sslKey) > 0) {
@@ -274,9 +268,19 @@ func awss3(w http.ResponseWriter, r *http.Request) {
274268
path := r.URL.Path
275269
rangeHeader := r.Header.Get("Range")
276270

271+
// Strip the prefix, if it's present.
277272
if len(c.stripPath) > 0 {
278-
path = strings.Replace(path, c.stripPath, "", 1)
273+
path = strings.TrimPrefix(path, c.stripPath)
279274
}
275+
276+
// If there is a health check path defined, and if this path matches it,
277+
// then return 200 OK and return.
278+
// Note: we want to apply the health check *after* the prefix is stripped.
279+
if len(c.healthCheckPath) > 0 && path == c.healthCheckPath {
280+
w.WriteHeader(http.StatusOK)
281+
return
282+
}
283+
280284
idx := strings.Index(path, "symlink.json")
281285
if idx > -1 {
282286
result, err := s3get(c.s3Bucket, c.s3KeyPrefix+path[:idx+12], rangeHeader)

0 commit comments

Comments
 (0)