Allow async lambdas. Other socket modifications.

This commit is contained in:
Dominik Picheta 2014-06-19 00:05:27 +01:00
commit 7ebbc09578
4 changed files with 25 additions and 12 deletions

View file

@ -14,12 +14,13 @@
import strtabs, asyncnet, asyncdispatch, parseutils, parseurl, strutils
type
TRequest* = object
client: PAsyncSocket # TODO: Separate this into a Response object?
client*: PAsyncSocket # TODO: Separate this into a Response object?
reqMethod*: string
headers*: PStringTable
protocol*: tuple[orig: string, major, minor: int]
url*: TURL
hostname*: string ## The hostname of the client that made the request.
body*: string # TODO
PAsyncHttpServer* = ref object
socket: PAsyncSocket
@ -169,6 +170,10 @@ proc serve*(server: PAsyncHttpServer, port: TPort,
var fut = await server.socket.acceptAddr()
processClient(fut.client, fut.address, callback)
proc close*(server: PAsyncHttpServer) =
## Terminates the async http server instance.
server.socket.close()
when isMainModule:
var server = newAsyncHttpServer()
proc cb(req: TRequest) {.async.} =