You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As title says. getFormParams crashes in the same manner. Is this a bug or is it supposed to happen? If it's supposed to happen how would I check that the post body is actually a form? Because I feel like getFormParamsOption should still return none(string) even if the body isn't a form.
running curl --form text=hello http://localhost:8080/testpost
works just fine but running curl -X POST -H "Content-Type: application/json" -d '{"text":"example1"}' http://localhost:8080/testpost
crashes the server. Error log:
$ nim r protest.nim
Hint: used config file '/home/bobbbob/.choosenim/toolchains/nim-2.0.8/config/nim.cfg' [Conf]
Hint: used config file '/home/bobbbob/.choosenim/toolchains/nim-2.0.8/config/config.nims' [Conf]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
10123 lines; 0.023s; 10.477MiB peakmem; proj: /home/bobbbob/protest.nim; out: /home/bobbbob/.cache/nim/protest_d/protest_EB947FA496BB993984B6850599C2BDE955F9E454 [SuccessX]
Hint: /home/bobbbob/.cache/nim/protest_d/protest_EB947FA496BB993984B6850599C2BDE955F9E454 [Exec]
DEBUG Prologue is serving at http://0.0.0.0:8080
DEBUG Starting 16 threads
DEBUG Listening on port 8080
Traceback (most recent call last)
/home/bobbbob/.choosenim/toolchains/nim-2.0.8/lib/system.nim(568) eventLoop
/home/bobbbob/.nimble/pkgs2/httpx-0.3.7-6e0fc3133fbd20530d53ab2792e93d3151387b10/httpx.nim(478) processEvents
/home/bobbbob/.nimble/pkgs2/prologue-0.6.6-433777a19c0bf630753006f0646c5a6dbbfd4b74/prologue/core/application.nim(536) handler
/home/bobbbob/.nimble/pkgs2/prologue-0.6.6-433777a19c0bf630753006f0646c5a6dbbfd4b74/prologue/core/application.nim(501) handleRequest
/home/bobbbob/.nimble/pkgs2/prologue-0.6.6-433777a19c0bf630753006f0646c5a6dbbfd4b74/prologue/core/application.nim(460) handleContext (Async)
/home/bobbbob/.nimble/pkgs2/prologue-0.6.6-433777a19c0bf630753006f0646c5a6dbbfd4b74/prologue/core/middlewaresbase.nim(48) switch (Async)
/home/bobbbob/protest.nim(7) testPost (Async)
/home/bobbbob/.nimble/pkgs2/prologue-0.6.6-433777a19c0bf630753006f0646c5a6dbbfd4b74/prologue/core/context.nim(392) getFormParamsOption
/home/bobbbob/.choosenim/toolchains/nim-2.0.8/lib/pure/collections/tables.nim(1916) contains
/home/bobbbob/.choosenim/toolchains/nim-2.0.8/lib/pure/collections/tables.nim(1906) hasKey
/home/bobbbob/.choosenim/toolchains/nim-2.0.8/lib/pure/collections/tables.nim(1418) hasKey
/home/bobbbob/.choosenim/toolchains/nim-2.0.8/lib/pure/collections/hashcommon.nim(42) rawGet
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)
Error: execution of an external program failed: '/home/bobbbob/.cache/nim/protest_d/protest_EB947FA496BB993984B6850599C2BDE955F9E454'
The text was updated successfully, but these errors were encountered:
Note that: getFormParams handles both form-urlencoded and multipart/form-data
So I don't think there a way to get the json param easily with a function. But you can see that inside ctx.request.body you actually have your data (although it is of type string). In order not to crash, you should check whether the Content-Type matches, for instance
if ctx.request.headers["Content-Type"] notin@["application/x-www-form-urlencoded", "multipart/form-data"]:
resp"<h1>Not found</h1>"return
As title says. getFormParams crashes in the same manner. Is this a bug or is it supposed to happen? If it's supposed to happen how would I check that the post body is actually a form? Because I feel like getFormParamsOption should still return none(string) even if the body isn't a form.
Example code:
running
curl --form text=hello http://localhost:8080/testpost
works just fine but running
curl -X POST -H "Content-Type: application/json" -d '{"text":"example1"}' http://localhost:8080/testpost
crashes the server. Error log:
The text was updated successfully, but these errors were encountered: