aboutsummaryrefslogtreecommitdiff
path: root/uri.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-08-17 18:55:32 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-08-17 18:55:32 +0300
commit2662f2e1f4c031c3202361eee923b64c5e02beed (patch)
treee5ff520392d707c0920ecf2eaf64e5232d04517e /uri.go
parentDetect overriden TLS connections in RequestCtx.IsTLS and RequestCtx.TLSConnec... (diff)
downloadfasthttp-2662f2e1f4c031c3202361eee923b64c5e02beed.tar.gz
fasthttp-2662f2e1f4c031c3202361eee923b64c5e02beed.tar.bz2
fasthttp-2662f2e1f4c031c3202361eee923b64c5e02beed.zip
Allow redirecting to urls without scheme, i.e. //google.com/foo.bar
Diffstat (limited to 'uri.go')
-rw-r--r--uri.go30
1 files changed, 21 insertions, 9 deletions
diff --git a/uri.go b/uri.go
index 48a445e..43060de 100644
--- a/uri.go
+++ b/uri.go
@@ -395,6 +395,22 @@ func (u *URI) updateBytes(newURI, buf []byte) []byte {
if len(newURI) == 0 {
return buf
}
+
+ n := bytes.Index(newURI, strSlashSlash)
+ if n >= 0 {
+ // absolute uri
+ var b [32]byte
+ schemeOriginal := b[:0]
+ if len(u.scheme) > 0 {
+ schemeOriginal = append([]byte(nil), u.scheme...)
+ }
+ u.Parse(nil, newURI)
+ if len(schemeOriginal) > 0 && len(u.scheme) == 0 {
+ u.scheme = append(u.scheme[:0], schemeOriginal...)
+ }
+ return buf
+ }
+
if newURI[0] == '/' {
// uri without host
buf = u.appendSchemeHost(buf[:0])
@@ -403,13 +419,6 @@ func (u *URI) updateBytes(newURI, buf []byte) []byte {
return buf
}
- n := bytes.Index(newURI, strColonSlashSlash)
- if n >= 0 {
- // absolute uri
- u.Parse(nil, newURI)
- return buf
- }
-
// relative path
switch newURI[0] {
case '?':
@@ -467,7 +476,7 @@ func (u *URI) String() string {
}
func splitHostURI(host, uri []byte) ([]byte, []byte, []byte) {
- n := bytes.Index(uri, strColonSlashSlash)
+ n := bytes.Index(uri, strSlashSlash)
if n < 0 {
return strHTTP, host, uri
}
@@ -475,7 +484,10 @@ func splitHostURI(host, uri []byte) ([]byte, []byte, []byte) {
if bytes.IndexByte(scheme, '/') >= 0 {
return strHTTP, host, uri
}
- n += len(strColonSlashSlash)
+ if len(scheme) > 0 && scheme[len(scheme)-1] == ':' {
+ scheme = scheme[:len(scheme)-1]
+ }
+ n += len(strSlashSlash)
uri = uri[n:]
n = bytes.IndexByte(uri, '/')
if n < 0 {