Skip to content

Commit

Permalink
Merge pull request #7 from yuzuy/fix_makeheaderfromdefaultheader
Browse files Browse the repository at this point in the history
Fix makeHeaderFromDefaultHeader
  • Loading branch information
yuzuy authored Feb 28, 2021
2 parents 3d892bb + ceb3273 commit bf16d31
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/gurl/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"regexp"
"sort"
"strings"
)

Expand Down Expand Up @@ -103,8 +104,15 @@ func makeHTTPRequest(uri *url.URL, cf configFile) (*http.Request, error) {
}

func makeHeaderFromDefaultHeader(uri *url.URL, cf configFile) (http.Header, error) {
patterns := make([]string, 0, len(cf))
for pattern := range cf {
patterns = append(patterns, pattern)
}
sort.Strings(patterns)

header := make(http.Header)
for pattern, conf := range cf {
for _, pattern := range patterns {
fmt.Println(pattern)
pattern = strings.ReplaceAll(pattern, "/", "\\/")
pattern = strings.ReplaceAll(pattern, "*", ".*")
regex, err := regexp.Compile("^" + pattern + "$")
Expand All @@ -118,7 +126,7 @@ func makeHeaderFromDefaultHeader(uri *url.URL, cf configFile) (http.Header, erro
continue
}

for k, v := range conf.Header {
for k, v := range cf[pattern].Header {
header.Set(k, v)
}
}
Expand Down

0 comments on commit bf16d31

Please sign in to comment.