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

http: windows - make https requests work in threads

This commit is contained in:
joe-conigliaro
2019-08-29 19:33:20 +10:00
committed by Alexander Medvednikov
parent 4f62e8235f
commit cd625b04eb
3 changed files with 138 additions and 143 deletions

View File

@ -4,9 +4,6 @@
module http
import strings
import net.urllib
#flag windows -I @VROOT/thirdparty/vschannel
#flag -l ws2_32
@ -14,15 +11,19 @@ import net.urllib
#include "vschannel.c"
fn C.new_tls_context() C.TlsContext
fn init_module() {}
fn (req &Request) ssl_do(port int, method, host_name, path string) Response {
C.vschannel_init()
mut ctx := C.new_tls_context()
C.vschannel_init(&ctx)
mut buff := malloc(C.vsc_init_resp_buff_size)
addr := host_name
sdata := req.build_request_headers(method, host_name, path)
length := int(C.request(port, addr.str, sdata.str, &buff))
length := int(C.request(&ctx, port, addr.str, sdata.str, &buff))
C.vschannel_cleanup()
C.vschannel_cleanup(&ctx)
return parse_response(string(buff, length))
}