net.http: add ability to parametrize the read and write timeouts of a http request (#10482)
parent
7b52dbfdf8
commit
b2e2a53f98
|
@ -7,6 +7,7 @@ import io
|
||||||
import net
|
import net
|
||||||
import net.urllib
|
import net.urllib
|
||||||
import strings
|
import strings
|
||||||
|
import time
|
||||||
|
|
||||||
// Request holds information about an HTTP request (either received by
|
// Request holds information about an HTTP request (either received by
|
||||||
// a server or to be sent by a client)
|
// a server or to be sent by a client)
|
||||||
|
@ -21,6 +22,10 @@ pub mut:
|
||||||
user_agent string = 'v.http'
|
user_agent string = 'v.http'
|
||||||
verbose bool
|
verbose bool
|
||||||
user_ptr voidptr
|
user_ptr voidptr
|
||||||
|
// NOT implemented for ssl connections
|
||||||
|
// time = -1 for no timeout
|
||||||
|
read_timeout i64 = 30 * time.second
|
||||||
|
write_timeout i64 = 30 * time.second
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut req Request) free() {
|
fn (mut req Request) free() {
|
||||||
|
@ -138,6 +143,8 @@ fn (req &Request) http_do(host string, method Method, path string) ?Response {
|
||||||
host_name, _ := net.split_address(host) ?
|
host_name, _ := net.split_address(host) ?
|
||||||
s := req.build_request_headers(method, host_name, path)
|
s := req.build_request_headers(method, host_name, path)
|
||||||
mut client := net.dial_tcp(host) ?
|
mut client := net.dial_tcp(host) ?
|
||||||
|
client.set_read_timeout(req.read_timeout)
|
||||||
|
client.set_write_timeout(req.write_timeout)
|
||||||
// TODO this really needs to be exposed somehow
|
// TODO this really needs to be exposed somehow
|
||||||
client.write(s.bytes()) ?
|
client.write(s.bytes()) ?
|
||||||
$if trace_http_request ? {
|
$if trace_http_request ? {
|
||||||
|
|
Loading…
Reference in New Issue