http: Windows fixes
parent
7d5f29dbd1
commit
5baff9beda
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
module http
|
module http
|
||||||
|
|
||||||
#flag -lwininet
|
import time
|
||||||
|
|
||||||
|
#flag -lwininet -lShlwapi
|
||||||
#flag -lurlmon
|
#flag -lurlmon
|
||||||
// #include <WinInet.h>
|
#include <WinInet.h>
|
||||||
#include "urlmon.h"
|
#include "urlmon.h"
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
// #LPWSTR winstring(string s);
|
// #LPWSTR winstring(string s);
|
||||||
|
@ -22,10 +24,10 @@ fn (req &Request) do() Response {
|
||||||
mut s := ''
|
mut s := ''
|
||||||
emptyresp := Response{}
|
emptyresp := Response{}
|
||||||
mut url := req.url
|
mut url := req.url
|
||||||
println('\n\nhttp.do() WIN URL="$url" TYP=$req.typ data="$req.data" headers.len=req.headers.len"')
|
//println('\n\nhttp.do() WIN URL="$url" TYP=$req.typ data="$req.data" headers.len=req.headers.len"')
|
||||||
println(req.headers)
|
//println(req.headers)
|
||||||
is_ssl := req.url.starts_with('https://')
|
is_ssl := req.url.starts_with('https://')
|
||||||
println('is ssl=$is_ssl')
|
//println('is ssl=$is_ssl')
|
||||||
mut pos := url.index('/')
|
mut pos := url.index('/')
|
||||||
url = url.right(pos + 2)
|
url = url.right(pos + 2)
|
||||||
mut host := url
|
mut host := url
|
||||||
|
@ -116,7 +118,7 @@ fn (req &Request) do() Response {
|
||||||
// LPVOID lpOutBuffer=malloc(dwSize);
|
// LPVOID lpOutBuffer=malloc(dwSize);
|
||||||
# HttpQueryInfo(request, HTTP_QUERY_RAW_HEADERS_CRLF,
|
# HttpQueryInfo(request, HTTP_QUERY_RAW_HEADERS_CRLF,
|
||||||
# h_buf,&dwSize,NULL);
|
# h_buf,&dwSize,NULL);
|
||||||
# printf(" resp HEADERS %s\n", h_buf);
|
//# printf(" resp HEADERS %s\n", h_buf);
|
||||||
// Get response body
|
// Get response body
|
||||||
// # const int BUF_MAX = 1024;
|
// # const int BUF_MAX = 1024;
|
||||||
// # TCHAR buf[BUF_MAX + 1];
|
// # 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)
|
// # while ((InternetReadFile(request, buf, BUF_MAX, &nr_read)) && nr_read > 0)
|
||||||
for
|
for
|
||||||
{
|
{
|
||||||
println('111')
|
|
||||||
ok := C.InternetReadFile(request, buf, BUF_MAX, &nr_read)
|
ok := C.InternetReadFile(request, buf, BUF_MAX, &nr_read)
|
||||||
println('222')
|
|
||||||
if !ok {
|
if !ok {
|
||||||
println('InternetReadFile() not ok ')
|
println('InternetReadFile() not ok ')
|
||||||
}
|
}
|
||||||
if ok && nr_read == 0 {
|
if ok && nr_read == 0 {
|
||||||
println('ok && nr read == 0, breaking')
|
//println('ok && nr read == 0, breaking')
|
||||||
C.printf('buf broken="%s"\n', buf)
|
//C.printf('buf broken="%s"\n', buf)
|
||||||
if req.url.contains('websocket') {
|
if req.url.contains('websocket') {
|
||||||
println('win sleeping 2')
|
println('win sleeping 2')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
@ -153,10 +153,11 @@ fn (req &Request) do() Response {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
println('ireadfile()')
|
//println('ireadfile()')
|
||||||
buf[nr_read] = 0
|
buf[nr_read] = 0
|
||||||
C.printf('buf="%s"\n', buf)
|
//C.printf('buf="%s"\n', buf)
|
||||||
s += string(buf)// TODO perf
|
|
||||||
|
s += tos(buf, nr_read + 1) // TODO perf
|
||||||
nr_read = 0
|
nr_read = 0
|
||||||
}
|
}
|
||||||
C.InternetCloseHandle(request)
|
C.InternetCloseHandle(request)
|
||||||
|
@ -174,16 +175,16 @@ fn (req &Request) do() Response {
|
||||||
// println('\n!')
|
// println('\n!')
|
||||||
// println(h)
|
// println(h)
|
||||||
vals := h.split(':')
|
vals := h.split(':')
|
||||||
pos := h.index(':')
|
hpos := h.index(':')
|
||||||
if pos == -1 {
|
if pos == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
key := h.left(pos)
|
key := h.left(hpos)
|
||||||
val := h.right(pos + 1)
|
val := h.right(hpos + 1)
|
||||||
// println('$key => $val')
|
// println('$key => $val')
|
||||||
resp.headers[key] = val.trim_space()
|
resp.headers[key] = val.trim_space()
|
||||||
}
|
}
|
||||||
println('END OF WIN req.do($req.url)')
|
//println('END OF WIN req.do($req.url)')
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue