diff options
author | Sergey Ponomarev <stokito@gmail.com> | 2021-11-08 14:35:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 13:35:26 +0100 |
commit | 3ff6aaa5917f40eeb5cdcb4272c58210f161f0ea (patch) | |
tree | 53ec8a4c5463d22aae967de353bc12e995da0152 /uri.go | |
parent | http.go: Request.SetURI() (Fix #1141) (#1148) (diff) | |
download | fasthttp-3ff6aaa5917f40eeb5cdcb4272c58210f161f0ea.tar.gz fasthttp-3ff6aaa5917f40eeb5cdcb4272c58210f161f0ea.tar.bz2 fasthttp-3ff6aaa5917f40eeb5cdcb4272c58210f161f0ea.zip |
uri: isHttps() and isHttp() (#1150)
* uri: isHttps() and isHttp()
Use them instead of manual schema comparison
* uri: use SetSchemeBytes()
Diffstat (limited to 'uri.go')
-rw-r--r-- | uri.go | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -216,6 +216,14 @@ func (u *URI) SetSchemeBytes(scheme []byte) { lowercaseBytes(u.scheme) } +func (u *URI) isHttps() bool { + return bytes.Equal(u.scheme, strHTTPS) +} + +func (u *URI) isHttp() bool { + return len(u.scheme) == 0 || bytes.Equal(u.scheme, strHTTP) +} + // Reset clears uri. func (u *URI) Reset() { u.pathOriginal = u.pathOriginal[:0] @@ -282,14 +290,13 @@ func (u *URI) parse(host, uri []byte, isTLS bool) error { if len(host) == 0 || bytes.Contains(uri, strColonSlashSlash) { scheme, newHost, newURI := splitHostURI(host, uri) - u.scheme = append(u.scheme, scheme...) - lowercaseBytes(u.scheme) + u.SetSchemeBytes(scheme) host = newHost uri = newURI } if isTLS { - u.scheme = append(u.scheme[:0], strHTTPS...) + u.SetSchemeBytes(strHTTPS) } if n := bytes.IndexByte(host, '@'); n >= 0 { |