Skip to content

Commit

Permalink
Merge pull request #141 from fastly/dkegel-pluggable-urlparser
Browse files Browse the repository at this point in the history
fsthttp: SetParseRequestURI now lets you register a url parser
  • Loading branch information
dkegel-fastly authored Sep 12, 2024
2 parents 8a5d69d + e911cbb commit 53f369c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fsthttp/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func NewRequest(method string, uri string, body io.Reader) (*Request, error) {
}, nil
}

// _parseRequestURI can be set by SetParseRequestURI
var _parseRequestURI func(string)(*url.URL, error) = url.ParseRequestURI

func newClientRequest() (*Request, error) {
abiReq, abiReqBody, err := fastly.BodyDownstreamGet()
if err != nil {
Expand All @@ -149,7 +152,7 @@ func newClientRequest() (*Request, error) {
return nil, fmt.Errorf("get URI: %w", err)
}

u, err := url.ParseRequestURI(uri)
u, err := _parseRequestURI(uri)
if err != nil {
return nil, fmt.Errorf("parse URI: %w", err)
}
Expand Down
14 changes: 14 additions & 0 deletions fsthttp/setparseuri.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build fastlyinternalsetparseuri

package fsthttp

import (
"net/url"
)

// SetParseRequestURI takes a function like url.ParseRequestURI to use when parsing incoming requests
// It is an experimental interface for applications that want to relax restrictions on url parsing
// It should generally not be needed, and is likely to change, so please avoid unless absolutely necessary
func SetParseRequestURI(parseRequestURI func(string)(*url.URL, error)) {
_parseRequestURI = parseRequestURI
}

0 comments on commit 53f369c

Please sign in to comment.