path must start with /

pull/1639/head
Joe Conigliaro 2019-08-17 23:29:18 +10:00 committed by Alexander Medvednikov
parent 4f8acca153
commit 1274cdf0af
1 changed files with 5 additions and 3 deletions

View File

@ -113,11 +113,12 @@ pub fn (req &Request) do() Response {
} }
// first request // first request
mut u := if url.query().size > 0 { '$url.path?${url.query().encode()}' } else { url.path } mut p := url.path.trim_left('/')
mut u := if url.query().size > 0 { '/$p?${url.query().encode()}' } else { '/$p' }
mut resp := ssl_do(req.typ, url.hostname(), u) mut resp := ssl_do(req.typ, url.hostname(), u)
// follow any redirects // follow any redirects
mut no_redirects := 0 mut no_redirects := 0
for resp.status_code in [301, 302, 303, 307 ,308] { for resp.status_code in [301, 302, 303, 307, 308] {
if no_redirects == max_redirects { if no_redirects == max_redirects {
panic('http.request.do: maximum number of redirects reached ($max_redirects)') panic('http.request.do: maximum number of redirects reached ($max_redirects)')
} }
@ -125,7 +126,8 @@ pub fn (req &Request) do() Response {
r_url := urllib.parse(h_loc) or { r_url := urllib.parse(h_loc) or {
panic('http.request.do: cannot follow redirect, location header has invalid url $h_loc') panic('http.request.do: cannot follow redirect, location header has invalid url $h_loc')
} }
u = if r_url.query().size > 0 { '$r_url.path?${r_url.query().encode()}' } else { r_url.path } p = r_url.path.trim_left('/')
u = if r_url.query().size > 0 { '/$p?${r_url.query().encode()}' } else { '/$p' }
resp = ssl_do(req.typ, r_url.hostname(), u) resp = ssl_do(req.typ, r_url.hostname(), u)
no_redirects++ no_redirects++
} }