Skip to content

Commit e911cbb

Browse files
committed
fsthttp: SetParseRequestURI now lets you register a replacement for url.ParseRequestURI
This is like #136 but more suitable for polite company, with less bloat, less opinion about the right way to parse urls, and near zero overhead unless opted in. The change is behind its own little build tag, fastlyinternalsetparseuri, because it may be needed at different times than the things behind our other private api build tag. Tested with sigsci-edge, for which a PR will soon be forthcoming.
1 parent 8a5d69d commit e911cbb

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)