Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Apr 12, 2024
1 parent d4937be commit ff9622b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/scorper/http/httpcore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func getOrDefault*(headers: HttpHeaders, key: string,
## Returns the values associated with the given ``key``. If there are no
## values associated with the key, then ``default`` is returned.
if headers.hasKey(key):
return headers.getOrDefault(headers.toCaseInsensitive(key))
return headers.table.getOrDefault(headers.toCaseInsensitive(key)).HttpHeaderValues
else:
return default

Expand Down
13 changes: 8 additions & 5 deletions src/scorper/http/streamserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ template devLog(req: ImpRequest, content: untyped) =
template handleCompress(needCompress: bool; content: string; ctn: var string; length: var int) =
if needCompress:
headers.ContentEncoding "gzip"
ctn = compress(content, BestSpeed, dfGzip)
try:
ctn = compress(content, BestSpeed, dfGzip)
except ZippyError:

length = ctn.len
else:
when defined(gcArc) or defined(gcOrc):
Expand Down Expand Up @@ -192,7 +195,7 @@ proc resp*(req: ImpRequest, content: sink string,
await resp(req, content, headers.newHttpHeaders())

proc respError*(req: ImpRequest, code: HttpCode, content: sink string, headers = newHttpHeaders()): Future[
void] {.async.} =
void] {.async:(raises:[]).} =
## Responds to the req with the specified ``HttpCode``.
if req.responded == true:
return
Expand All @@ -212,10 +215,10 @@ proc respError*(req: ImpRequest, code: HttpCode, content: sink string, headers =
req.responded = true

proc respError*(req: ImpRequest, code: HttpCode, content: sink string,
headers: seq[(string, string)]): Future[void] {.inline, async.} =
headers: seq[(string, string)]): Future[void] {.inline, async: (raises:[]).} =
await respError(req, code, content, headers.newHttpHeaders())

proc respError*(req: ImpRequest, code: HttpCode, headers = newHttpHeaders()): Future[void] {.async.} =
proc respError*(req: ImpRequest, code: HttpCode, headers = newHttpHeaders()): Future[void] {.async:(raises: []).} =
## Responds to the req with the specified ``HttpCode``.
if req.responded == true:
return
Expand Down Expand Up @@ -624,7 +627,7 @@ proc postCheck(req: ImpRequest): Future[int]{.async, inline.} =
if req.meth in MethodNeedsBody and req.parsed == false:
result = await req.reader.consume(req.contentLength.int)

proc defaultErrorHandle(req: ImpRequest, err: ref Exception | HttpError; headers = newHttpHeaders()){.async, gcsafe.} =
proc defaultErrorHandle(req: ImpRequest, err: ref Exception | HttpError; headers = newHttpHeaders()){.async: (raises: []), gcsafe.} =
if req.responded:
return
let code = when err is HttpError: err.code.HttpCode else: Http500 #
Expand Down

0 comments on commit ff9622b

Please sign in to comment.