1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net.http: more robust handling of relative /path URL redirects

This commit is contained in:
Delyan Angelov
2020-02-12 15:52:39 +02:00
committed by GitHub
parent 67e7ad13de
commit 0ad5d53423
5 changed files with 25 additions and 7 deletions

View File

@@ -193,7 +193,7 @@ pub fn parse_headers(lines []string) map[string]string {
// do will send the HTTP request and returns `http.Response` as soon as the response is recevied
pub fn (req &Request) do() ?Response {
url := urllib.parse(req.url) or {
mut url := urllib.parse(req.url) or {
return error('http.Request.do: invalid url ${req.url}')
}
mut rurl := url
@@ -211,7 +211,13 @@ pub fn (req &Request) do() ?Response {
break
}
// follow any redirects
redirect_url := resp.headers['Location']
mut redirect_url := resp.headers['Location']
if redirect_url.len > 0 && redirect_url[0] == `/` {
url.set_path(redirect_url) or {
return error('http.request.do: invalid path in redirect: "$redirect_url"')
}
redirect_url = url.str()
}
qrurl := urllib.parse(redirect_url) or {
return error('http.request.do: invalid URL in redirect "$redirect_url"')
}