Add HttpDisconnectError to avoid client processor notification call.

This commit is contained in:
cheatfate 2021-02-11 08:32:25 +02:00 committed by zah
parent 1789328748
commit 6f8d06f12d
2 changed files with 11 additions and 4 deletions

View File

@ -25,6 +25,7 @@ type
code*: HttpCode
HttpRecoverableError* = object of HttpError
code*: HttpCode
HttpDisconnectError* = object of HttpError
TransferEncodingFlags* {.pure.} = enum
Identity, Chunked, Compress, Deflate, Gzip
@ -80,6 +81,11 @@ proc newHttpRecoverableError*(msg: string,
tre.code = code
tre
proc newHttpDisconnectError*(): ref HttpDisconnectError {.
raises: [HttpDisconnectError].} =
var tre = newException(HttpDisconnectError, "Remote peer disconnected")
tre
iterator queryParams*(query: string): tuple[key: string, value: string] {.
raises: [Defect].} =
## Iterate over url-encoded query string.

View File

@ -429,10 +429,8 @@ proc getRequest(conn: HttpConnectionRef): Future[HttpRequestRef] {.async.} =
raise newHttpCriticalError("Invalid request received", res.error)
else:
return res.get()
except AsyncStreamIncompleteError:
raise newHttpCriticalError("Remote peer disconnected")
except AsyncStreamReadError:
raise newHttpCriticalError("Connection with remote peer has been lost")
except AsyncStreamIncompleteError, AsyncStreamReadError:
raise newHttpDisconnectError()
except AsyncStreamLimitError:
raise newHttpCriticalError("Maximum size of request headers reached",
Http413)
@ -561,6 +559,9 @@ proc processLoop(server: HttpServerRef, transp: StreamTransport) {.async.} =
let error = HttpProcessError.init(HTTPServerError.CriticalError, exc,
transp.remoteAddress(), exc.code)
arg = RequestFence[HttpRequestRef].err(error)
except HttpDisconnectError:
# If remote peer disconnected we just exiting loop
breakLoop = true
except CatchableError as exc:
let error = HttpProcessError.init(HTTPServerError.CatchableError, exc,
transp.remoteAddress(), Http500)