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

http/vweb: use Method enum & add helpers

This commit is contained in:
joe-conigliaro
2020-07-28 14:13:19 +10:00
parent fec9920b1a
commit 395e886b2e
2 changed files with 40 additions and 21 deletions

View File

@ -75,6 +75,37 @@ pub fn new_request(method Method, url_, data string) ?Request {
}
}
fn (methods []Method) contains(m Method) bool {
for method in methods {
if method == m {
return true
}
}
return false
}
fn (m Method) str() string {
return match m {
.get { 'GET' }
.post { 'POST' }
.header { 'HEADER' }
.put { 'PUT' }
.connect { 'CONNECT' }
else { '' }
}
}
pub fn method_from_str(m string) Method {
return match m {
'GET' { Method.get }
'POST' { Method.post }
'HEADER' { Method.header }
'PUT' { Method.put }
'CONNECT' { Method.connect }
else { Method.get } // should we default to GET?
}
}
pub fn get(url string) ?Response {
return fetch_with_method(.get, url, FetchConfig{})
}
@ -383,17 +414,6 @@ fn (req &Request) build_request_headers(method Method, host_name, path string) s
req.data
}
fn (m Method) str() string {
return match m {
.get { 'GET' }
.post { 'POST' }
.header { 'HEADER' }
.put { 'PUT' }
.connect { 'CONNECT' }
else { '' }
}
}
fn (req &Request) build_request_cookies_header() string {
if req.cookies.keys().len < 1 {
return ''