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

http: use urllib.parse

This commit is contained in:
joe-conigliaro 2019-08-06 22:43:09 +10:00 committed by Alexander Medvednikov
parent 1b2e49be1c
commit 60d206c29d

View File

@ -4,6 +4,8 @@
module http module http
import net.urllib
struct Request { struct Request {
pub: pub:
headers2 []string headers2 []string
@ -97,23 +99,15 @@ pub fn (req &Request) do() Response {
for key, val in req.headers { for key, val in req.headers {
//h := '$key: $val' //h := '$key: $val'
} }
mut url := req.url url := urllib.parse(req.url) or {
mut host := url // panic('http.request.do: invalid URL $req.url'
mut path := '/' return Response{} //error('ff')}
is_ssl := req.url.starts_with('https://') }
is_ssl := url.scheme == 'https'
if !is_ssl { if !is_ssl {
panic('non https requests are not supported right now') panic('non https requests are not supported right now')
}
mut pos := url.index('://')
if pos == -1 { return Response{} } //error('ff')}
url = url.right(pos + 3)
pos = url.index('/')
if pos > -1 {
host = url.left(pos)
host = host.clone()
path = url.right(pos)
} }
s := ssl_do(req.typ, host, path) s := ssl_do(req.typ, url.host, url.path)
first_header := s.all_before('\n') first_header := s.all_before('\n')
mut status_code := 0 mut status_code := 0
if first_header.contains('HTTP/') { if first_header.contains('HTTP/') {
@ -137,7 +131,7 @@ pub fn (req &Request) do() Response {
break break
} }
i++ i++
pos = h.index(':') pos := h.index(':')
if pos == -1 { if pos == -1 {
continue continue
} }