Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce compiler warnings #154

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions websock/http/server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type
template used(x: typed) =
# silence unused warning
discard

proc validateRequest(
stream: AsyncStreamWriter,
header: HttpRequestHeader): Future[ReqStatus] {.async.} =
Expand Down Expand Up @@ -124,7 +124,7 @@ proc parseRequest(

proc handleConnCb(
server: StreamServer,
transp: StreamTransport) {.async: (raises: []).} =
transp: StreamTransport) {.gcsafe, async: (raises: []).} =
var stream: AsyncStream
try:
stream = AsyncStream(
Expand All @@ -136,42 +136,54 @@ proc handleConnCb(

await httpServer.handler(request)
except CatchableError as exc:
used(exc)
used(exc)
debug "Exception in HttpHandler", exc = exc.msg
finally:
try:
await stream.closeWait()
except CatchableError as exc:
used(exc)
debug "Exception in HttpHandler closewait", exc = exc.msg

proc handleTlsConnCb(
server: StreamServer,
transp: StreamTransport) {.async.} =
transp: StreamTransport) {.gcsafe, async: (raises: []).} =

let tlsHttpServer = TlsHttpServer(server)
let tlsStream = newTLSServerAsyncStream(
newAsyncStreamReader(transp),
newAsyncStreamWriter(transp),
tlsHttpServer.tlsPrivateKey,
tlsHttpServer.tlsCertificate,
minVersion = tlsHttpServer.minVersion,
maxVersion = tlsHttpServer.maxVersion,
flags = tlsHttpServer.tlsFlags)
var tlsStream: TLSAsyncStream

try:
tlsStream = newTLSServerAsyncStream(
newAsyncStreamReader(transp),
newAsyncStreamWriter(transp),
tlsHttpServer.tlsPrivateKey,
tlsHttpServer.tlsCertificate,
minVersion = tlsHttpServer.minVersion,
maxVersion = tlsHttpServer.maxVersion,
flags = tlsHttpServer.tlsFlags)
except CatchableError as exc:
used(exc)
debug "Exception when initialize TLS stream", exc = exc.msg
return

let stream = AsyncStream(
reader: tlsStream.reader,
writer: tlsStream.writer)

try:
let httpServer = HttpServer(server)
let request = await httpServer.parseRequest(stream)

await httpServer.handler(request)
except CatchableError as exc:
used(exc)
debug "Exception in HttpHandler", exc = exc.msg
debug "Exception in HttpsHandler", exc = exc.msg
finally:
await stream.closeWait()
try:
await stream.closeWait()
except CatchableError as exc:
used(exc)
debug "Exception in HttpsHandler closewait", exc = exc.msg

proc accept*(server: HttpServer): Future[HttpRequest] {.async.} =
if not isNil(server.handler):
Expand Down Expand Up @@ -263,7 +275,7 @@ proc create*(
headersTimeout = HttpHeadersTimeout,
handshakeTimeout = 0.seconds
): TlsHttpServer
{.raises: [Defect, CatchableError].} = # TODO: remove CatchableError
{.raises: [CatchableError].} = # TODO: remove CatchableError

var server = TlsHttpServer(
headersTimeout: headersTimeout,
Expand Down