From 5baff9beda54df3f858a1ae46ecdc6a7e00e04fc Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 12 Jul 2019 16:26:02 +0200 Subject: [PATCH] http: Windows fixes --- vlib/http/http_win.v | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/vlib/http/http_win.v b/vlib/http/http_win.v index 7b6b0e6823..cafe2c82f2 100644 --- a/vlib/http/http_win.v +++ b/vlib/http/http_win.v @@ -4,9 +4,11 @@ module http -#flag -lwininet +import time + +#flag -lwininet -lShlwapi #flag -lurlmon -// #include +#include #include "urlmon.h" #include // #LPWSTR winstring(string s); @@ -22,10 +24,10 @@ fn (req &Request) do() Response { mut s := '' emptyresp := Response{} mut url := req.url - println('\n\nhttp.do() WIN URL="$url" TYP=$req.typ data="$req.data" headers.len=req.headers.len"') - println(req.headers) + //println('\n\nhttp.do() WIN URL="$url" TYP=$req.typ data="$req.data" headers.len=req.headers.len"') + //println(req.headers) is_ssl := req.url.starts_with('https://') - println('is ssl=$is_ssl') + //println('is ssl=$is_ssl') mut pos := url.index('/') url = url.right(pos + 2) mut host := url @@ -116,7 +118,7 @@ fn (req &Request) do() Response { // LPVOID lpOutBuffer=malloc(dwSize); # HttpQueryInfo(request, HTTP_QUERY_RAW_HEADERS_CRLF, # h_buf,&dwSize,NULL); - # printf(" resp HEADERS %s\n", h_buf); + //# printf(" resp HEADERS %s\n", h_buf); // Get response body // # const int BUF_MAX = 1024; // # TCHAR buf[BUF_MAX + 1]; @@ -137,15 +139,13 @@ fn (req &Request) do() Response { // # while ((InternetReadFile(request, buf, BUF_MAX, &nr_read)) && nr_read > 0) for { - println('111') ok := C.InternetReadFile(request, buf, BUF_MAX, &nr_read) - println('222') if !ok { println('InternetReadFile() not ok ') } if ok && nr_read == 0 { - println('ok && nr read == 0, breaking') - C.printf('buf broken="%s"\n', buf) + //println('ok && nr read == 0, breaking') + //C.printf('buf broken="%s"\n', buf) if req.url.contains('websocket') { println('win sleeping 2') time.sleep(2) @@ -153,10 +153,11 @@ fn (req &Request) do() Response { } break } - println('ireadfile()') + //println('ireadfile()') buf[nr_read] = 0 - C.printf('buf="%s"\n', buf) - s += string(buf)// TODO perf + //C.printf('buf="%s"\n', buf) + + s += tos(buf, nr_read + 1) // TODO perf nr_read = 0 } C.InternetCloseHandle(request) @@ -174,16 +175,16 @@ fn (req &Request) do() Response { // println('\n!') // println(h) vals := h.split(':') - pos := h.index(':') + hpos := h.index(':') if pos == -1 { continue } - key := h.left(pos) - val := h.right(pos + 1) + key := h.left(hpos) + val := h.right(hpos + 1) // println('$key => $val') resp.headers[key] = val.trim_space() } - println('END OF WIN req.do($req.url)') + //println('END OF WIN req.do($req.url)') return resp }