Merge branch 'bigbreak' of https://github.com/Araq/Nimrod into bigbreak
Conflicts: lib/pure/asynchttpserver.nim
This commit is contained in:
commit
c7116cc121
2 changed files with 7 additions and 7 deletions
|
|
@ -58,7 +58,7 @@ proc addHeaders(msg: var string, headers: PStringTable) =
|
||||||
for k, v in headers:
|
for k, v in headers:
|
||||||
msg.add(k & ": " & v & "\c\L")
|
msg.add(k & ": " & v & "\c\L")
|
||||||
|
|
||||||
proc sendHeaders*(req: TRequest, headers: PStringTable): PFuture[void] =
|
proc sendHeaders*(req: TRequest, headers: PStringTable): Future[void] =
|
||||||
## Sends the specified headers to the requesting client.
|
## Sends the specified headers to the requesting client.
|
||||||
var msg = ""
|
var msg = ""
|
||||||
addHeaders(msg, headers)
|
addHeaders(msg, headers)
|
||||||
|
|
@ -96,12 +96,12 @@ proc parseProtocol(protocol: string): tuple[orig: string, major, minor: int] =
|
||||||
i.inc # Skip .
|
i.inc # Skip .
|
||||||
i.inc protocol.parseInt(result.minor, i)
|
i.inc protocol.parseInt(result.minor, i)
|
||||||
|
|
||||||
proc sendStatus(client: PAsyncSocket, status: string): PFuture[void] =
|
proc sendStatus(client: PAsyncSocket, status: string): Future[void] =
|
||||||
client.send("HTTP/1.1 " & status & "\c\L")
|
client.send("HTTP/1.1 " & status & "\c\L")
|
||||||
|
|
||||||
proc processClient(client: PAsyncSocket, address: string,
|
proc processClient(client: PAsyncSocket, address: string,
|
||||||
callback: proc (request: TRequest):
|
callback: proc (request: TRequest):
|
||||||
PFuture[void] {.closure, gcsafe.}) {.async.} =
|
Future[void] {.closure, gcsafe.}) {.async.} =
|
||||||
while true:
|
while true:
|
||||||
# GET /path HTTP/1.1
|
# GET /path HTTP/1.1
|
||||||
# Header: val
|
# Header: val
|
||||||
|
|
@ -188,7 +188,7 @@ proc processClient(client: PAsyncSocket, address: string,
|
||||||
break
|
break
|
||||||
|
|
||||||
proc serve*(server: PAsyncHttpServer, port: Port,
|
proc serve*(server: PAsyncHttpServer, port: Port,
|
||||||
callback: proc (request: TRequest): PFuture[void] {.closure,gcsafe.},
|
callback: proc (request: TRequest): Future[void] {.closure,gcsafe.},
|
||||||
address = "") {.async.} =
|
address = "") {.async.} =
|
||||||
## Starts the process of listening for incoming HTTP connections on the
|
## Starts the process of listening for incoming HTTP connections on the
|
||||||
## specified address and port.
|
## specified address and port.
|
||||||
|
|
@ -220,6 +220,6 @@ when isMainModule:
|
||||||
"Content-type": "text/plain; charset=utf-8"}
|
"Content-type": "text/plain; charset=utf-8"}
|
||||||
await req.respond(Http200, "Hello World", headers.newStringTable())
|
await req.respond(Http200, "Hello World", headers.newStringTable())
|
||||||
|
|
||||||
asyncCheck server.serve(TPort(5555), cb)
|
asyncCheck server.serve(Port(5555), cb)
|
||||||
runForever()
|
runForever()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,7 @@ proc recvLine*(socket: PAsyncSocket,
|
||||||
return
|
return
|
||||||
add(result.string, c)
|
add(result.string, c)
|
||||||
|
|
||||||
proc listen*(socket: Socket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
|
proc listen*(socket: PAsyncSocket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
|
||||||
## Marks ``socket`` as accepting connections.
|
## Marks ``socket`` as accepting connections.
|
||||||
## ``Backlog`` specifies the maximum length of the
|
## ``Backlog`` specifies the maximum length of the
|
||||||
## queue of pending connections.
|
## queue of pending connections.
|
||||||
|
|
@ -343,7 +343,7 @@ proc listen*(socket: Socket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
|
||||||
## Raises an EOS error upon failure.
|
## Raises an EOS error upon failure.
|
||||||
if listen(socket.fd, backlog) < 0'i32: raiseOSError(osLastError())
|
if listen(socket.fd, backlog) < 0'i32: raiseOSError(osLastError())
|
||||||
|
|
||||||
proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
|
proc bindAddr*(socket: PAsyncSocket, port = Port(0), address = "") {.
|
||||||
tags: [ReadIOEffect].} =
|
tags: [ReadIOEffect].} =
|
||||||
## Binds ``address``:``port`` to the socket.
|
## Binds ``address``:``port`` to the socket.
|
||||||
##
|
##
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue