aboutsummaryrefslogtreecommitdiff
path: root/uri.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2021-10-03 10:30:20 +0200
committerGravatar Erik Dubbelboer <erik@dubbelboer.com> 2021-10-03 10:30:20 +0200
commitad6d128614269a4d621e74b3d8cd31d9f549583e (patch)
tree355452b95c4695e5652931040bedbe7e43651741 /uri.go
parentImprove return value reusability documentation (diff)
downloadfasthttp-ad6d128614269a4d621e74b3d8cd31d9f549583e.tar.gz
fasthttp-ad6d128614269a4d621e74b3d8cd31d9f549583e.tar.bz2
fasthttp-ad6d128614269a4d621e74b3d8cd31d9f549583e.zip
URI.Parse should never change it's input
Decode the URI in place, but use the bytes of the URI instead of the bytes of the input parameter.
Diffstat (limited to 'uri.go')
-rw-r--r--uri.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/uri.go b/uri.go
index 061e11e..2285f45 100644
--- a/uri.go
+++ b/uri.go
@@ -305,11 +305,12 @@ func (u *URI) parse(host, uri []byte, isTLS bool) error {
}
}
- host, err := parseHost(host)
- if err != nil {
+ u.host = append(u.host, host...)
+ if parsedHost, err := parseHost(u.host); err != nil {
return err
+ } else {
+ u.host = parsedHost
}
- u.host = append(u.host, host...)
lowercaseBytes(u.host)
b := uri
@@ -353,6 +354,8 @@ func (u *URI) parse(host, uri []byte, isTLS bool) error {
// information. That is, as host[:port].
//
// Based on https://github.com/golang/go/blob/8ac5cbe05d61df0a7a7c9a38ff33305d4dcfea32/src/net/url/url.go#L619
+//
+// The host is parsed and unescaped in place overwriting the contents of the host parameter.
func parseHost(host []byte) ([]byte, error) {
if len(host) > 0 && host[0] == '[' {
// Parse an IP-Literal in RFC 3986 and RFC 6874.
@@ -425,6 +428,8 @@ func (e InvalidHostError) Error() string {
// which section of the URL string is being unescaped.
//
// Based on https://github.com/golang/go/blob/8ac5cbe05d61df0a7a7c9a38ff33305d4dcfea32/src/net/url/url.go#L199
+//
+// Unescapes in place overwriting the contents of s and returning it.
func unescape(s []byte, mode encoding) ([]byte, error) {
// Count %, check that they're well-formed.
n := 0