diff --git a/puppy.nimble b/puppy.nimble index 573959a..605b073 100644 --- a/puppy.nimble +++ b/puppy.nimble @@ -1,4 +1,4 @@ -version = "1.2.0" +version = "1.2.1" author = "Andre von Houck" description = "Puppy fetches HTML pages for Nim." license = "MIT" diff --git a/src/puppy/windefs.nim b/src/puppy/windefs.nim index b047272..0231b89 100644 --- a/src/puppy/windefs.nim +++ b/src/puppy/windefs.nim @@ -287,7 +287,9 @@ proc SysFreeString*(bstrString: BSTR): void {.importc, stdcall, dynlib: "oleaut3 proc SysStringLen *(bstrString: BSTR): UINT {.importc, stdcall, dynlib: "oleaut32".} proc VariantInit*(pvarg: ptr VARIANT): void {.importc, stdcall, dynlib: "oleaut32".} proc VariantClear*(pvarg: ptr VARIANT): void {.importc, stdcall, dynlib: "oleaut32".} -proc SafeArrayGetDim*(psa: ptr SAFEARRAY): UINT {.importc, stdcall, dynlib: "oleaut32".} +proc SafeArrayCreate*(vt: VARTYPE, cDims: UINT, rgsabound: ptr SAFEARRAYBOUND): ptr SAFEARRAY {.importc, stdcall, dynlib: "oleaut32".} +proc SafeArrayGetDim*(psa: ptr SAFEARRAY): HRESULT {.importc, stdcall, dynlib: "oleaut32".} +proc SafeArrayDestroy*(psa: ptr SAFEARRAY): UINT {.importc, stdcall, dynlib: "oleaut32".} proc SafeArrayGetUBound*(psa: ptr SAFEARRAY, nDim: UINT, plUbound: ptr LONG): HRESULT {.importc, stdcall, dynlib: "oleaut32".} proc SafeArrayGetLBound*(psa: ptr SAFEARRAY, nDim: UINT, plLbound: ptr LONG): HRESULT {.importc, stdcall, dynlib: "oleaut32".} proc SafeArrayAccessData*(psa: ptr SAFEARRAY, ppvData: ptr pointer): HRESULT {.importc, stdcall, dynlib: "oleaut32".} diff --git a/src/puppy/winhttp.nim b/src/puppy/winhttp.nim index d5595fa..5fa47da 100644 --- a/src/puppy/winhttp.nim +++ b/src/puppy/winhttp.nim @@ -136,9 +136,19 @@ proc send*(http: WinHttp, body: string = "") = if body == "": variantBody.union1.struct1.vt = VT_ERROR else: - let bodyBstr = body.bstr() - variantBody.union1.struct1.vt = VT_BSTR - variantBody.union1.struct1.union1.bstrVal = bodyBstr + var bounds: SAFEARRAYBOUND + bounds.lLbound = 0 + bounds.cElements = body.len.ULONG + + let psa = SafeArrayCreate(VT_UI1, 1, bounds.addr) + + var p: pointer + checkHRESULT(SafeArrayAccessData(psa, p.addr)) + copyMem(p, body[0].unsafeAddr, body.len) + checkHRESULT(SafeArrayUnaccessData(psa)) + + variantBody.union1.struct1.vt = (VT_ARRAY or VT_UI1) + variantBody.union1.struct1.union1.parray = psa let hresult = http.i.lpVtbl.Send(http.i, variantBody) VariantClear(variantBody.addr) diff --git a/tests/debug_client.nim b/tests/debug_client.nim index 00a4346..1ba754e 100644 --- a/tests/debug_client.nim +++ b/tests/debug_client.nim @@ -50,21 +50,20 @@ for i in 0 ..< 100: doAssert res.code == 200 doAssert res.body == "some data" - when not defined(windows): - block: - # test post + gzip - let res = fetch(Request( - url: parseUrl("http://localhost:8080/postgzip"), - headers: @[ - Header(key: "Accept-Encoding", value: "gzip"), - # Header(key: "Content-Type", value: "text/html; charset=UTF-8"), - Header(key: "Content-Encoding", value: "gzip") - ], - verb: "post", - body: compress("gzip'ed request body", BestSpeed, dfGzip), - )) - doAssert res.code == 200 - doAssert res.body == "gzip'ed request body" + block: + # test post + gzip + let res = fetch(Request( + url: parseUrl("http://localhost:8080/postgzip"), + headers: @[ + Header(key: "Accept-Encoding", value: "gzip"), + # Header(key: "Content-Type", value: "text/html; charset=UTF-8"), + Header(key: "Content-Encoding", value: "gzip") + ], + verb: "post", + body: compress("gzip'ed request body", BestSpeed, dfGzip), + )) + doAssert res.code == 200 + doAssert res.body == "gzip'ed request body" block: # test headers