Skip to content

Commit 7131121

Browse files
committed
Generalize fields with multiple params
1 parent 1c38961 commit 7131121

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

httpparse.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ func parseRequest(req *http.Request) (*parsedMessage, error) {
2727
if err != nil {
2828
return nil, fmt.Errorf("cannot parse query: %s", req.URL.RawQuery)
2929
}
30-
url := req.URL
31-
if url.Host == "" {
32-
url.Host = req.Host
30+
u := req.URL
31+
if u.Host == "" {
32+
u.Host = req.Host
3333
}
34-
if url.Scheme == "" {
34+
if u.Scheme == "" {
3535
if req.TLS == nil {
36-
url.Scheme = "http"
36+
u.Scheme = "http"
3737
} else {
38-
url.Scheme = "https"
38+
u.Scheme = "https"
3939
}
4040
}
41-
return &parsedMessage{derived: generateReqDerivedComponents(req), url: url, headers: normalizeHeaderNames(req.Header), qParams: values}, nil
41+
return &parsedMessage{derived: generateReqDerivedComponents(req), url: u, headers: normalizeHeaderNames(req.Header), qParams: values}, nil
4242
}
4343

4444
func normalizeHeaderNames(header http.Header) http.Header {
45-
var t http.Header = http.Header{}
45+
var t = http.Header{}
4646
for k, v := range header {
4747
t[strings.ToLower(k)] = v
4848
}
@@ -77,20 +77,20 @@ func foldFields(fields []string) string {
7777
return ff
7878
}
7979

80-
func specialtyComponent(name, v string, components components) {
80+
func derivedComponent(name, v string, components components) {
8181
components[name] = v
8282
}
8383

8484
func generateReqDerivedComponents(req *http.Request) components {
8585
components := components{}
86-
specialtyComponent("@method", scMethod(req), components)
86+
derivedComponent("@method", scMethod(req), components)
8787
theURL := req.URL
88-
specialtyComponent("@target-uri", scTargetURI(theURL), components)
89-
specialtyComponent("@path", scPath(theURL), components)
90-
specialtyComponent("@authority", scAuthority(req), components)
91-
specialtyComponent("@scheme", scScheme(theURL), components)
92-
specialtyComponent("@request-target", scRequestTarget(theURL), components)
93-
specialtyComponent("@query", scQuery(theURL), components)
88+
derivedComponent("@target-uri", scTargetURI(theURL), components)
89+
derivedComponent("@path", scPath(theURL), components)
90+
derivedComponent("@authority", scAuthority(req), components)
91+
derivedComponent("@scheme", scScheme(theURL), components)
92+
derivedComponent("@request-target", scRequestTarget(theURL), components)
93+
derivedComponent("@query", scQuery(theURL), components)
9494
// @request-response does not belong here
9595
return components
9696
}
@@ -128,7 +128,7 @@ func scMethod(req *http.Request) string {
128128

129129
func generateResDerivedComponents(res *http.Response) components {
130130
components := components{}
131-
specialtyComponent("@status", scStatus(res), components)
131+
derivedComponent("@status", scStatus(res), components)
132132
return components
133133
}
134134

signatures.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ func GetRequestSignature(req *http.Request, signatureName string) (string, error
297297
}
298298
ws, err := parsedMessage.getDictHeader("signature", signatureName)
299299
if err != nil {
300-
return "", fmt.Errorf("missing \"signature\" header for \"%s\"", signatureName)
300+
return "", fmt.Errorf("missing \"Signature\" header for \"%s\"", signatureName)
301301
}
302302
if len(ws) > 1 {
303-
return "", fmt.Errorf("more than one \"signature\" value for \"%s\"", signatureName)
303+
return "", fmt.Errorf("more than one \"Signature\" value for \"%s\"", signatureName)
304304
}
305305
sigHeader := ws[0]
306306
sigRaw, err := parseWantSignature(sigHeader)
@@ -313,10 +313,10 @@ func GetRequestSignature(req *http.Request, signatureName string) (string, error
313313
func messageKeyID(signatureName string, parsedMessage parsedMessage) (keyID, alg string, err error) {
314314
si, err := parsedMessage.getDictHeader("signature-input", signatureName)
315315
if err != nil {
316-
return "", "", fmt.Errorf("missing \"signature-input\" header, or cannot find \"%s\": %w", signatureName, err)
316+
return "", "", fmt.Errorf("missing \"Signature-Input\" header, or cannot find \"%s\": %w", signatureName, err)
317317
}
318318
if len(si) > 1 {
319-
return "", "", fmt.Errorf("more than one \"signature-input\" for %s", signatureName)
319+
return "", "", fmt.Errorf("more than one \"Signature-Input\" for %s", signatureName)
320320
}
321321
signatureInput := si[0]
322322
psi, err := parseSignatureInput(signatureInput, signatureName)

0 commit comments

Comments
 (0)