async - noob question

2021-03-17 Thread mantielero
This is the code that I am using to play with, which is rubbish (I know), but does what I expect. I was trying to use [googleapi](https://github.com/treeform/googleapi) from @treeform. But it uses service accounts, which doesn't work for my use case. import oauth2 import struti

async - noob question

2021-03-17 Thread mantielero
For some reason, when I tried to use just `serve` in my code I had issues. I just want to create an http server that receives one controlled request and that's it. The only solution that I have managed to make work in a controlled manner is the one using: await server.acceptReque

async - noob question

2021-03-17 Thread dom96
I would suggest just using `serve`. Why are you playing with the `acceptRequest` proc?

async - noob question

2021-03-16 Thread ynfle
It seems like you missing the following line: if server.shouldAcceptRequest(): Run Not sure if that'd make a difference, but please do tell.

async - noob question

2021-03-16 Thread mantielero
A better solution seems to be: await server.acceptRequest(cb) drain() Run but I still don't get how `waitFor` works. It doesn't seem to block the required ammount of time.

async - noob question

2021-03-16 Thread mantielero
It works with: import std/[asyncdispatch, asynchttpserver]#, os proc main {.async.} = const port = 8080 var server = newAsyncHttpServer() proc cb(req: Request) {.async.} = echo (req.reqMethod, req.url, req.headers) let headers = {"Con

async - noob question

2021-03-16 Thread mantielero
Still playing with this (trying to actually understand what is going on). I have the following code: import std/[asyncdispatch, asynchttpserver]#, os proc main {.async.} = const port = 8080 var server = newAsyncHttpServer() proc cb(req: Request) {.a

async - noob question

2021-03-15 Thread timothee
=> followup for a proposal on how to improve this

async - noob question

2021-03-15 Thread mantielero
Understood. But I think most people would tend to copy/paste the example. Regarding the original question on this thread, now everything works as expected by avoiding using the global variable. I finally used: import std/[asyncdispatch,asynchttpserver] proc main {.async.}

async - noob question

2021-03-15 Thread Yardanico
"Understood. But I think most people would tend to copy/paste the example." I personally think so to, but see

async - noob question

2021-03-15 Thread Yardanico
It's not wrong, "asynchttpserver" is not there because the example is in the module itself.

async - noob question

2021-03-15 Thread mantielero
Regarding the example, it seems that I hit the issues already reported [here](https://forum.my-toolbox.xyz/t/7295) and [here](https://forum.nim-lang.org/t/7565#47981) -associated to this [bug](https://github.com/nim-lang/Nim/issues/16506)-. I updated to Nim1.4.4 and use the example from [devel

async - noob question

2021-03-14 Thread mantielero
I was trying to encapsulate everything in a proc rather than state , without success. In fact, I tried the code in [this example](https://nim-lang.org/docs/asynchttpserver.html#example) and I get a similar error: /home/jose/src/nimlang/google/server2.nim(3, 13) template/generic

async - noob question

2021-03-14 Thread dom96
oh, am I understanding correctly that you're spinning up an HTTP server to authenticate your users in a desktop app and that is the reason you want to close the server as soon as the auth completes? If so I would say that you can use global vars in your code, but I would recommend a different w

async - noob question

2021-03-14 Thread mantielero
First thanks for your advices. You were right that I was trying to do so from the browser. It is ok with curl. What I am trying to do is to perfom oauth2 authenticaton with google. So basically I open a browser where I give permission to the app, and that makes a call to something that looks li

async - noob question

2021-03-14 Thread dom96
Yeah, as @enthus1ast said. You're getting multiple requests from your browser, use `echo req.url` to make it clear. Best to test with `curl` to understand what's going on. The error you're getting happens because of Nim's gc safety mechanism. You cannot access global variables in a `gcsafe` cal

async - noob question

2021-03-14 Thread enthus1ast
I think you get the 3 several times, when you test this in a browser, correct? This is because browsers do several requests implicitly, in your case it could be that the browser try to fetch the site's favicon. This should not happen when you test with curl or "by hand" with netcat. For the gc

async - noob question

2021-03-14 Thread mantielero
Let me rephrase what I am trying to do: import asynchttpserver, asyncdispatch#, cgi var server = newAsyncHttpServer() echo "1" proc cb(req: Request) {.async.} = echo req.url.query echo "3" await req.respond(Http200, "Hello World", newHttpHeader

async - noob question

2021-03-14 Thread ynfle
Checkout [httpsbeast](https://github.com/dom96/httpbeast). It's an async webserver written in nim.

async - noob question

2021-03-14 Thread sekao
Not sure if this is what you want but check out the other thread going on right now: In particular @Araq posted a nice example of an http server that just uses a threadpool and no async code:

async - noob question

2021-03-14 Thread mantielero
I am not familiar at all about `async`. I am trying to reuse the following code: import asynchttpserver, asyncdispatch proc main {.async.} = var server = newAsyncHttpServer() proc cb(req: Request) {.async.} = let headers = {"Date": "Tue, 29 Apr 2014 23:4