Skip to content

Commit

Permalink
curl tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
guzba committed Jan 31, 2024
1 parent 5c57e11 commit d3cbea2
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/puppy/platforms/linux/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ type StringWrap = object
## some sort of wrapper to be passed to C.
str: string

{.push stackTrace: off.}

proc curlWriteFn(
buffer: cstring,
size: int,
count: int,
outstream: pointer
): int {.cdecl.} =
let
outbuf = cast[ptr StringWrap](outstream)
i = outbuf.str.len
outbuf.str.setLen(outbuf.str.len + count)
copyMem(outbuf.str[i].addr, buffer, count)
result = size * count

{.pop.}

proc internalFetch*(req: Request): Response {.raises: [PuppyError].} =
result = Response()

{.push stackTrace: off.}

proc curlWriteFn(
buffer: cstring,
size: int,
count: int,
outstream: pointer
): int {.cdecl.} =
let
outbuf = cast[ptr StringWrap](outstream)
i = outbuf.str.len
outbuf.str.setLen(outbuf.str.len + count)
copyMem(outbuf.str[i].addr, buffer, count)
result = size * count

{.pop.}

var strings: seq[string]
strings.add $req.url
strings.add req.verb.toUpperAscii()
Expand Down Expand Up @@ -65,11 +65,12 @@ proc internalFetch*(req: Request): Response {.raises: [PuppyError].} =

discard curl.easy_setopt(OPT_HTTPHEADER, headerList)

if req.verb.toUpperAscii() == "HEAD":
if cmpIgnoreCase(req.verb, "HEAD") == 0:
discard curl.easy_setopt(OPT_NOBODY, 1)
elif req.verb.toUpperAscii() == "POST" or req.body.len > 0:
elif cmpIgnoreCase(req.verb, "POST") == 0 or req.body.len > 0:
discard curl.easy_setopt(OPT_POSTFIELDSIZE, req.body.len)
discard curl.easy_setopt(OPT_POSTFIELDS, req.body.cstring)
if req.body.len > 0:
discard curl.easy_setopt(OPT_POSTFIELDS, req.body.cstring)

# Setup writers.
var headerWrap, bodyWrap: StringWrap
Expand Down

0 comments on commit d3cbea2

Please sign in to comment.