Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akarashchuk committed Apr 26, 2024
1 parent 1034bc1 commit 8047799
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
3 changes: 1 addition & 2 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func GetCache(name string) Cache {
func buildRedisCnf(input map[string]interface{}) (*rd.Options, error) {
var config RedisCnf

err := mapstructure.WeakDecode(input, &config)
if err != nil {
if err := mapstructure.WeakDecode(input, &config); err != nil {
return nil, err
}

Expand Down
31 changes: 14 additions & 17 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type SrvConfig struct {

func NewClientConfig(input map[string]interface{}) (*ClientConfig, error) {
var config ClientConfig
err := parseConfig(input, &config)
if err != nil {

if err := parseConfig(input, &config); err != nil {
return nil, err
}

Expand All @@ -34,8 +34,8 @@ func NewClientConfig(input map[string]interface{}) (*ClientConfig, error) {

func NewSrvConfig(input map[string]interface{}) (*SrvConfig, error) {
var config SrvConfig
err := parseConfig(input, &config)
if err != nil {

if err := parseConfig(input, &config); err != nil {
return nil, err
}

Expand All @@ -48,23 +48,20 @@ func parseConfig(input map[string]interface{}, output interface{}) error {
return errors.New("configuration not found")
}

err := mapstructure.WeakDecode(cnf, &output)
if err != nil {
return err
}

return nil
return mapstructure.WeakDecode(cnf, &output)
}

func normalizeHeaders(headers []string) []string {
res := make(map[string]bool)
for _, h := range headers {
res[textproto.CanonicalMIMEHeaderKey(h)] = true
}

seen := make(map[string]bool)
var values []string
for h := range res {
values = append(values, h)

for _, h := range headers {
h = textproto.CanonicalMIMEHeaderKey(h)
if _, ok := seen[h]; !ok {
seen[h] = true
values = append(values, h)
}
seen[textproto.CanonicalMIMEHeaderKey(h)] = true
}

slices.Sort(values)
Expand Down
7 changes: 2 additions & 5 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,12 @@ func cacheKey(req *http.Request, cnf *ClientConfig) string {

var headers []string
for _, h := range cnf.Headers {
val := req.Header.Values(h)
if val != nil {
if val := req.Header.Values(h); val != nil {
headers = append(headers, fmt.Sprintf("%s:%s", strings.ToLower(h), strings.Join(val, ",")))
}
}

if len(headers) > 0 {
url = fmt.Sprintf("%s|headers:%s", url, strings.Join(headers, "/"))
}
url += "|headers:" + strings.Join(headers, "/")

return fmt.Sprintf("krakend-hc:%s", uuid.NewSHA1(uuid.NameSpaceURL, []byte(url)))
}

0 comments on commit 8047799

Please sign in to comment.