Skip to content

Commit

Permalink
fix: REQUEST_HEADER tags search on replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
achetronic committed Oct 10, 2024
1 parent 58255b9 commit 150ce3e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion charts/hashrouter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type: application
description: >-
A Helm chart for hashrouter, a A zero-dependencies HTTP proxy
that truly routes requests hash-consistently
version: &chartVersionSpec 0.11.0 # chart version
version: &chartVersionSpec 0.11.1 # chart version
appVersion: *chartVersionSpec # application version
kubeVersion: ">=1.22.0-0" # kubernetes version
home: https://github.com/achetronic/hashrouter
Expand Down
13 changes: 6 additions & 7 deletions internal/proxy/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package proxy

import (
"hashrouter/internal/utils"
"net"
"net/http"
"regexp"
Expand Down Expand Up @@ -50,7 +49,7 @@ func ReplaceRequestTags(req *http.Request, textToProcess string) (result string)

result = RequestPartsPatternCompiled.ReplaceAllStringFunc(textToProcess, func(match string) string {

variable := RequestPartsPatternCompiled.FindStringSubmatch(match)[1]
variable := strings.ToLower(RequestPartsPatternCompiled.FindStringSubmatch(match)[1])

if replacement, exists := requestTags[variable]; exists {
return replacement
Expand All @@ -68,8 +67,8 @@ func ReplaceRequestHeaderTags(req *http.Request, textToProcess string) (result s

result = RequestHeadersPatternCompiled.ReplaceAllStringFunc(textToProcess, func(match string) string {

variable := RequestHeadersPatternCompiled.FindStringSubmatch(match)[1]
headerValue := req.Header.Get(utils.CapitalizeWords(variable))
variable := strings.ToLower(RequestHeadersPatternCompiled.FindStringSubmatch(match)[1])
headerValue := req.Header.Get(variable)

return headerValue
})
Expand All @@ -83,8 +82,8 @@ func ReplaceResponseHeaderTags(res *http.Response, textToProcess string) (result

result = ResponseHeadersPatternCompiled.ReplaceAllStringFunc(textToProcess, func(match string) string {

variable := ResponseHeadersPatternCompiled.FindStringSubmatch(match)[1]
headerValue := res.Header.Get(utils.CapitalizeWords(variable))
variable := strings.ToLower(ResponseHeadersPatternCompiled.FindStringSubmatch(match)[1])
headerValue := res.Header.Get(variable)

return headerValue
})
Expand All @@ -99,7 +98,7 @@ func ReplaceExtraTags(extra ConnectionExtraData, textToProcess string) (result s

result = ExtraPatternCompiled.ReplaceAllStringFunc(textToProcess, func(match string) string {

variable := ExtraPatternCompiled.FindStringSubmatch(match)[1]
variable := strings.ToLower(ExtraPatternCompiled.FindStringSubmatch(match)[1])

switch variable {
case "request-id":
Expand Down
17 changes: 0 additions & 17 deletions internal/utils/utils.go

This file was deleted.

0 comments on commit 150ce3e

Please sign in to comment.