Skip to content

Commit

Permalink
reduce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Apr 12, 2024
1 parent 9e27b1f commit f72fa03
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
1 change: 1 addition & 0 deletions scorper.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ requires "npeg"
requires "zippy"
requires "jsony"
requires "urlly >= 0.2.0 & < 0.3.0"
requires "ptr_math"


task docs,"a":
Expand Down
8 changes: 4 additions & 4 deletions src/scorper/http/cookies.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type
None, Lax, Strict

# name, value, Expires, Max-Age, Domain, Path, Secure, HttpOnly, SameSite
proc makeCookie*(key, value, maxAge = "", expires = "", domain = "", path = "",
secure = false, httpOnly = false,
proc makeCookie*(key, value, maxAge, expires, domain, path:string;
secure = false; httpOnly = false;
sameSite = Lax): string =
# If both Expires and Max-Age are set, Max-Age has precedence.
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
Expand All @@ -22,8 +22,8 @@ proc makeCookie*(key, value, maxAge = "", expires = "", domain = "", path = "",
if sameSite != None:
result.add("; SameSite=" & $sameSite)

proc addCookie*(headers: HttpHeaders, name, value, maxAge = "", expires = "", domain = "", path = "",
secure = false, httpOnly = false,
proc addCookie*(headers: HttpHeaders, name, value, maxAge, expires, domain, path: string;
secure = false; httpOnly = false;
sameSite = Lax) =
# https://tools.ietf.org/html/draft-west-first-party-cookies-06
headers.add("Set-Cookie", makeCookie(name, value, maxAge, expires, domain, path, secure, httpOnly, sameSite))
Expand Down
2 changes: 1 addition & 1 deletion src/scorper/http/httperror.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type
code*: HttpErrorCode

proc newHttpError*(code: HttpErrorCode|HttpCode = 500.HttpErrorCode; msg = ""): HttpError =
new result
result = new HttpError
result.code = code.HttpErrorCode
if msg.len > 0:
result.msg = msg
Expand Down
4 changes: 2 additions & 2 deletions src/scorper/http/mofuparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ type
middle

template `+`[T](p: ptr T, off: int): ptr T =
cast[ptr type(p[])](cast[ByteAddress](p) +% off * sizeof(p[]))
cast[ptr type(p[])](cast[int](p) +% off * sizeof(p[]))

template `+=`[T](p: ptr T, off: int) =
p = p + off

template `-`[T](p: ptr T, off: int): ptr T =
cast[ptr type(p[])](cast[ByteAddress](p) -% off * sizeof(p[]))
cast[ptr type(p[])](cast[int](p) -% off * sizeof(p[]))

template `-`[T](p: ptr T, p2: ptr T): int =
cast[int](p) - cast[int](p2)
Expand Down
8 changes: 1 addition & 7 deletions src/scorper/http/multipartparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Copyright (c) 2020 Bung

import streams, os, oids, strformat
import chronos
import chronos, ptr_math
import parseutils, strutils # parseBoundary
include ./ constant
import ./sbmh
Expand Down Expand Up @@ -52,12 +52,6 @@ proc `$`*(x: ContentDisposition): string =
elif x.kind == file:
result = fmt"""{{"name":"{x.name}", "filename":"{x.filename}", "contentType": "{x.contentType}", "filepath": {x.filepath} }}"""

template `+`[T](p: ptr T, off: int): ptr T =
cast[ptr type(p[])](cast[ByteAddress](p) +% off * sizeof(p[]))

template `+=`[T](p: ptr T, off: int) =
p = p + off

template debug(a: varargs[untyped]) =
when defined(DebugMultipartParser):
echo a
Expand Down
8 changes: 1 addition & 7 deletions src/scorper/http/urlencodedparser.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include ./constant
import chronos
import chronos,ptr_math

type
UrlEncodedParserState* = enum
Expand Down Expand Up @@ -33,12 +33,6 @@ proc readOnce(parser: UrlEncodedParser): Future[int] {.async.} =
result = await parser.transp.readOnce(parser.src[0].addr, nbytes = parser.needReadLen)
parser.buf = parser.src[0].addr

template `+`[T](p: ptr T, off: int): ptr T =
cast[ptr type(p[])](cast[ByteAddress](p) +% off * sizeof(p[]))

template `+=`[T](p: ptr T, off: int) =
p = p + off

proc resetSlices(parser: UrlEncodedParser) {.inline.} =
parser.aSlice = default(Slice[int])
parser.bSlice = default(Slice[int])
Expand Down

0 comments on commit f72fa03

Please sign in to comment.