diff --git a/README.md b/README.md index 1d05870..afa944e 100644 --- a/README.md +++ b/README.md @@ -172,11 +172,10 @@ type headers*: HttpHeaders protocol*: tuple[major, minor: int] url*: Url - path*: string # http req path hostname*: string ip*: string params*: Table[string, string] - query*: seq[(string, string)] + ScorperCallback* = proc (req: Request): Future[void] {.closure, gcsafe.} Scorper* = ref object of StreamServer # inherited (partial) diff --git a/src/scorper/http/exts/resumable.nim b/src/scorper/http/exts/resumable.nim index 63bc582..997c660 100644 --- a/src/scorper/http/exts/resumable.nim +++ b/src/scorper/http/exts/resumable.nim @@ -54,7 +54,7 @@ proc isComplete*(resumable: Resumable): bool = proc handleResumableUpload*(req: Request; resumableKeys = newResumableKeys()): Future[ResumableResult]{.async.} = template resumableParam(key: untyped): untyped = - req.query[resumableKeys.`key`] + req.url.query[resumableKeys.`key`] var resumable: Resumable discard parseBiggestUInt(resumableParam(totalChunks), resumable.totalChunks) diff --git a/src/scorper/http/httprequest.nim b/src/scorper/http/httprequest.nim index 2efe2de..e6526db 100644 --- a/src/scorper/http/httprequest.nim +++ b/src/scorper/http/httprequest.nim @@ -8,9 +8,7 @@ type headers*: HttpHeaders protocol*: tuple[major, minor: int] url*: typeof(Url()[]) - path*: string # http req path hostname*: string ip*: string params*: Table[string, string] - query*: seq[(string, string)] - + \ No newline at end of file diff --git a/src/scorper/http/streamserver.nim b/src/scorper/http/streamserver.nim index 71407fe..5372d32 100644 --- a/src/scorper/http/streamserver.nim +++ b/src/scorper/http/streamserver.nim @@ -104,7 +104,7 @@ proc formatCommon*(r: ImpRequest, status: HttpCode, size: int): string = # LogFormat "%h %l %u %t \"%r\" %>s %b" common # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined let remoteUser = os.getEnv("REMOTE_USER", "-") - result = fmt"""{r.hostname} - {remoteUser} {$now()} "{r.meth} {r.path} HTTP/{r.protocol.major}.{r.protocol.minor}" {status} {size}""" + result = fmt"""{r.hostname} - {remoteUser} {$now()} "{r.meth} {r.url.path} HTTP/{r.protocol.major}.{r.protocol.minor}" {status} {size}""" proc genericHeaders(headers = newHttpHeaders()): lent HttpHeaders {.tags: [TimeEffect].} = ## genericHeaders contains Date,X-Frame-Options @@ -640,7 +640,7 @@ proc defaultErrorHandle(req: ImpRequest, err: ref Exception | HttpError; headers toUgly(s, %* {"error": err.msg}) await req.respError(code, s, headers) of "js": - let cbName: string = req.query["callback"] + let cbName: string = req.url.query["callback"] var s: string toUgly(s, %* {"error": err.msg}) await req.respError(code, fmt"""{cbName}({s});""", headers) @@ -712,10 +712,10 @@ proc processRequest( await req.respError(Http501) return true - req.path = scorper.httpParser.getPath() + let path = scorper.httpParser.getPath() const prefix = "http" & (when isSecurity: "s" else: "") & "://" try: - req.url = parseUrl(prefix & req.hostname & req.path)[] + req.url = parseUrl(prefix & req.hostname & path)[] except ValueError as e: scorper.logSub.next(e.msg) asyncSpawn req.respError(Http400) @@ -767,10 +767,6 @@ proc processRequest( var keep = true case scorper.kind of CbKind.cb: - when defined(gcArc) or defined(gcOrc): - req.query = move(req.url.query) - else: - shallowCopy(req.query, req.url.query) handlePreProcessMiddlewares(req) tryHandle(req, scorper.callback(req), keep) if not keep: @@ -780,10 +776,6 @@ proc processRequest( let matched = scorper.router.match($req.meth, req.url.path) if matched.success: req.params = matched.route.params[] - when defined(gcArc) or defined(gcOrc): - req.query = move(req.url.query) - else: - shallowCopy(req.query, req.url.query) req.prefix = matched.route.prefix handlePreProcessMiddlewares(req) tryHandle(req, matched.handler(req), keep)