all repos — min @ 1b3149c3de0e350a7f986dbe1010932c4659ecf4

A small but practical concatenative programming language.

Fixed HTTP module and tests.
h3rald h3rald@h3rald.com
Sat, 02 Jun 2018 22:21:15 +0200
commit

1b3149c3de0e350a7f986dbe1010932c4659ecf4

parent

0c8476c13c148cf388b89fccb1d538bdd74395a1

2 files changed, 17 insertions(+), 17 deletions(-)

jump to
M lib/min_http.nimlib/min_http.nim

@@ -1,4 +1,4 @@

-import httpclient, asynchttpserver, asyncdispatch, strutils, uri +import httpclient, asynchttpserver, asyncdispatch, strutils, uri, critbits import ../core/parser, ../core/consts,

@@ -12,9 +12,9 @@ proc newCli(): HttpClient =

return newHttpClient(userAgent = minUseragent) proc newVal(i: In, headers: HttpHeaders): MinValue = - result = newVal(newSeq[MinValue](), i.scope) + result = newDict(i.scope) for k, v in headers: - result = i.dset(result, k.newVal, v.newVal) + result = i.dset(result, k, v.newVal) type MinServerExit = ref object of SystemError

@@ -38,14 +38,14 @@ if req.dhas("headers"):

rawHeaders = i.dget(req, "headers") if not rawHeaders.isDictionary: raiseInvalid("Headers must be specified as a dictionary") - for v in rawHeaders.qVal: - headers[v.qVal[0].getString] = v.qVal[1].getString + for item in rawHeaders.dVal.pairs: + headers[item.key] = i.dget(rawHeaders, item.key).getString if req.dhas("body"): body = i.dget(req, "body") meth = i.dget(req, "method") url = i.dget(req, "url") let resp = cli.request(url = url.getString, httpMethod = meth.getString, body = body.getString, headers = headers) - var res = newVal(newSeq[MinValue](), i.scope) + var res = newDict(i.scope) res = i.dset(res, "version", resp.version.newVal) res = i.dset(res, "status", resp.status[0..2].parseInt.newVal) res = i.dset(res, "headers", i.newVal(resp.headers))

@@ -85,7 +85,7 @@ var server = newAsyncHttpServer()

var i {.threadvar.}: MinInterpreter i = ii proc handler(req: Request) {.async, gcsafe.} = - var qreq = newSeq[MinValue]().newVal(i.scope) + var qreq = newDict(i.scope) qreq = i.dset(qreq, "url", newVal($req.url)) qreq = i.dset(qreq, "headers", i.newVal(req.headers)) qreq = i.dset(qreq, "method", newVal($req.reqMethod))
M tests/http.mintests/http.min

@@ -11,25 +11,25 @@ ("$1/get?test=Hello!" (url) => % "tests/test1.json" :file file download file fread from-json /args /test "Hello!" ==) assert

"tests/test1.json" rm ( - () ( + {} ( ("$1/get?test=request" (url) => % %url) ("GET" %method) - ((("Accept-Language" "it-it")) %headers) + ({"it-it" :Accept-Language} %headers) (request) ) tap /body from-json /headers /Accept-Language "it-it" == ) assert ( - () ( + {} ( ("$1/put" (url) => % %url) ("PUT" %method) - ((("test" "put")) to-json %body) + ({"put" :test} to-json %body) (request) - ) tap /body from-json /json (("test" "put")) == + ) tap /body from-json /json {"put" :test} == ) assert ( - () ( + {} ( ("$1/post" (url) => % %url) ("POST" %method) ((("test" "post")) to-json %body)

@@ -38,16 +38,16 @@ ) tap /headers /content-type "application/json" ==

) assert ( - () ( + {} ( ("$1/patch" (url) => % %url) ("PATCH" %method) - ((("test" "patch")) to-json %body) + ({"patch" :test} to-json %body) (request) - ) tap /body from-json /json (("test" "patch")) == + ) tap /body from-json /json {"patch" :test} == ) assert ( - () ( + {} ( ("$1/delete" (url) => % %url) ("DELETE" %method) (request)