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

http: initial windows schannel http support

This commit is contained in:
joe-conigliaro
2019-08-09 20:52:14 +10:00
committed by Alexander Medvednikov
parent 181a39d752
commit d9a83481a5
6 changed files with 1246 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ import strings
#flag windows -I @VROOT/thirdparty/openssl/include
#flag darwin -I @VROOT/thirdparty/openssl/include
#flag -lssl -lcrypto
#flag -l ssl -l crypto
// MacPorts
#flag darwin -L/opt/local/lib
// Brew

30
vlib/http/backend_win.v Normal file
View File

@@ -0,0 +1,30 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module http
import strings
#flag windows -I @VROOT/thirdparty/vschannel
#flag -lws2_32 -lcrypt32
#include "vschannel.c"
fn init_module() {}
fn ssl_do(method, host_name, path string) string {
mut buff := malloc(10000)
req := '$method $path HTTP/1.0\r\nUser-Agent: v\r\nAccept:*/*\r\n\r\n'
length := int(C.request(host_name.str, req.str, buff))
if length == 0 {
return ''
}
resp := tos(buff, length)
return resp
}

View File

@@ -4,11 +4,15 @@
module http
#flag -l Urlmon
#include <Urlmon.h>
fn download_file_with_progress(url, out string, cb, cb_finished voidptr) {
}
pub fn download_file(url, out string) {
C.URLDownloadToFileW(0, url.to_wide(), out.to_wide(), 0, 0)
C.URLDownloadToFile(0, url.to_wide(), out.to_wide(), 0, 0)
/*
if (res == S_OK) {
println('Download Ok')

View File

@@ -108,7 +108,8 @@ pub fn (req &Request) do() Response {
if !is_ssl {
panic('non https requests are not supported right now')
}
s := ssl_do(req.typ, url.host, url.path)
s := ssl_do(req.typ, url.host, url.path)
// s := ssl_do(req.typ, url.host, url.path)
first_header := s.all_before('\n')
mut status_code := 0
if first_header.contains('HTTP/') {