Skip to content

Commit 53f369c

Browse files
Merge pull request #141 from fastly/dkegel-pluggable-urlparser
fsthttp: SetParseRequestURI now lets you register a url parser
2 parents 8a5d69d + e911cbb commit 53f369c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

fsthttp/request.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ func NewRequest(method string, uri string, body io.Reader) (*Request, error) {
133133
}, nil
134134
}
135135

136+
// _parseRequestURI can be set by SetParseRequestURI
137+
var _parseRequestURI func(string)(*url.URL, error) = url.ParseRequestURI
138+
136139
func newClientRequest() (*Request, error) {
137140
abiReq, abiReqBody, err := fastly.BodyDownstreamGet()
138141
if err != nil {
@@ -149,7 +152,7 @@ func newClientRequest() (*Request, error) {
149152
return nil, fmt.Errorf("get URI: %w", err)
150153
}
151154

152-
u, err := url.ParseRequestURI(uri)
155+
u, err := _parseRequestURI(uri)
153156
if err != nil {
154157
return nil, fmt.Errorf("parse URI: %w", err)
155158
}

fsthttp/setparseuri.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build fastlyinternalsetparseuri
2+
3+
package fsthttp
4+
5+
import (
6+
"net/url"
7+
)
8+
9+
// SetParseRequestURI takes a function like url.ParseRequestURI to use when parsing incoming requests
10+
// It is an experimental interface for applications that want to relax restrictions on url parsing
11+
// It should generally not be needed, and is likely to change, so please avoid unless absolutely necessary
12+
func SetParseRequestURI(parseRequestURI func(string)(*url.URL, error)) {
13+
_parseRequestURI = parseRequestURI
14+
}

0 commit comments

Comments
 (0)