Some small cleanup.
This commit is contained in:
parent
03cbf689a1
commit
62e1b3e2e3
2 changed files with 7 additions and 8 deletions
|
|
@ -21,10 +21,9 @@
|
||||||
##
|
##
|
||||||
## var server = newAsyncHttpServer()
|
## var server = newAsyncHttpServer()
|
||||||
## proc cb(req: Request) {.async.} =
|
## proc cb(req: Request) {.async.} =
|
||||||
## req.respond(Http200, "Hello World")
|
## await req.respond(Http200, "Hello World")
|
||||||
##
|
##
|
||||||
## asyncCheck server.serve(Port(8080), cb)
|
## waitFor server.serve(Port(8080), cb)
|
||||||
## runForever()
|
|
||||||
|
|
||||||
import strtabs, asyncnet, asyncdispatch, parseutils, uri, strutils
|
import strtabs, asyncnet, asyncdispatch, parseutils, uri, strutils
|
||||||
type
|
type
|
||||||
|
|
@ -38,7 +37,7 @@ type
|
||||||
body*: string
|
body*: string
|
||||||
|
|
||||||
AsyncHttpServer* = ref object
|
AsyncHttpServer* = ref object
|
||||||
socket*: AsyncSocket
|
socket: AsyncSocket
|
||||||
reuseAddr: bool
|
reuseAddr: bool
|
||||||
|
|
||||||
HttpCode* = enum
|
HttpCode* = enum
|
||||||
|
|
@ -112,9 +111,9 @@ proc sendHeaders*(req: Request, headers: StringTableRef): Future[void] =
|
||||||
proc respond*(req: Request, code: HttpCode, content: string,
|
proc respond*(req: Request, code: HttpCode, content: string,
|
||||||
headers: StringTableRef = nil): Future[void] =
|
headers: StringTableRef = nil): Future[void] =
|
||||||
## Responds to the request with the specified ``HttpCode``, headers and
|
## Responds to the request with the specified ``HttpCode``, headers and
|
||||||
## content. This template returns a Future[void].
|
## content.
|
||||||
##
|
##
|
||||||
## This template will **not** close the client socket.
|
## This procedure will **not** close the client socket.
|
||||||
var msg = "HTTP/1.1 " & $code & "\c\L"
|
var msg = "HTTP/1.1 " & $code & "\c\L"
|
||||||
|
|
||||||
if headers != nil:
|
if headers != nil:
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,13 @@ type
|
||||||
# TODO: I would prefer to just do:
|
# TODO: I would prefer to just do:
|
||||||
# AsyncSocket* {.borrow: `.`.} = distinct Socket. But that doesn't work.
|
# AsyncSocket* {.borrow: `.`.} = distinct Socket. But that doesn't work.
|
||||||
AsyncSocketDesc = object
|
AsyncSocketDesc = object
|
||||||
fd*: SocketHandle
|
fd: SocketHandle
|
||||||
closed: bool ## determines whether this socket has been closed
|
closed: bool ## determines whether this socket has been closed
|
||||||
case isBuffered: bool ## determines whether this socket is buffered.
|
case isBuffered: bool ## determines whether this socket is buffered.
|
||||||
of true:
|
of true:
|
||||||
buffer: array[0..BufferSize, char]
|
buffer: array[0..BufferSize, char]
|
||||||
currPos: int # current index in buffer
|
currPos: int # current index in buffer
|
||||||
bufLen*: int # current length of buffer
|
bufLen: int # current length of buffer
|
||||||
of false: nil
|
of false: nil
|
||||||
case isSsl: bool
|
case isSsl: bool
|
||||||
of true:
|
of true:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue