net.http: vfmt and remove unused ws_func

pull/10359/head
Alexander Medvednikov 2021-06-06 01:51:49 +03:00
parent 329a6c974e
commit aea93c3a96
2 changed files with 7 additions and 10 deletions

View File

@ -47,7 +47,7 @@ pub fn get(url string) ?Response {
pub fn post(url string, data string) ?Response {
return fetch_with_method(.post, url,
data: data
header: new_header({key: .content_type, value: http.content_type_default})
header: new_header(key: .content_type, value: http.content_type_default)
)
}
@ -55,14 +55,14 @@ pub fn post(url string, data string) ?Response {
pub fn post_json(url string, data string) ?Response {
return fetch_with_method(.post, url,
data: data
header: new_header({key: .content_type, value: 'application/json'})
header: new_header(key: .content_type, value: 'application/json')
)
}
// post_form sends a POST HTTP request to the URL with X-WWW-FORM-URLENCODED data
pub fn post_form(url string, data map[string]string) ?Response {
return fetch_with_method(.post, url,
header: new_header({key: .content_type, value: 'application/x-www-form-urlencoded'})
header: new_header(key: .content_type, value: 'application/x-www-form-urlencoded')
data: url_encode_form_data(data)
)
}
@ -71,7 +71,7 @@ pub fn post_form(url string, data map[string]string) ?Response {
pub fn put(url string, data string) ?Response {
return fetch_with_method(.put, url,
data: data
header: new_header({key: .content_type, value: http.content_type_default})
header: new_header(key: .content_type, value: http.content_type_default)
)
}
@ -79,7 +79,7 @@ pub fn put(url string, data string) ?Response {
pub fn patch(url string, data string) ?Response {
return fetch_with_method(.patch, url,
data: data
header: new_header({key: .content_type, value: http.content_type_default})
header: new_header(key: .content_type, value: http.content_type_default)
)
}
@ -107,7 +107,6 @@ pub fn fetch(_url string, config FetchConfig) ?Response {
header: config.header
cookies: config.cookies
user_agent: config.user_agent
ws_func: 0
user_ptr: 0
verbose: config.verbose
}

View File

@ -21,7 +21,6 @@ pub mut:
user_agent string = 'v.http'
verbose bool
user_ptr voidptr
ws_func voidptr
}
fn (mut req Request) free() {
@ -47,8 +46,8 @@ pub fn (req &Request) do() ?Response {
mut resp := Response{}
mut no_redirects := 0
for {
if no_redirects == http.max_redirects {
return error('http.request.do: maximum number of redirects reached ($http.max_redirects)')
if no_redirects == max_redirects {
return error('http.request.do: maximum number of redirects reached ($max_redirects)')
}
qresp := req.method_and_url_to_response(req.method, rurl) ?
resp = qresp
@ -256,7 +255,6 @@ struct MultiplePathAttributesError {
code int
}
fn parse_multipart_form(body string, boundary string) (map[string]string, map[string][]FileData) {
sections := body.split(boundary)
fields := sections[1..sections.len - 1]