Skip to content

Commit

Permalink
Merge pull request #29 from guzba/master
Browse files Browse the repository at this point in the history
winhttp upload binary
  • Loading branch information
treeform authored Sep 30, 2021
2 parents a81804e + f447c6d commit 1c4fa17
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion puppy.nimble
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/puppy/windefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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".}
Expand Down
16 changes: 13 additions & 3 deletions src/puppy/winhttp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 14 additions & 15 deletions tests/debug_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c4fa17

Please sign in to comment.