diff --git a/chronos/apps/http/httpclient.nim b/chronos/apps/http/httpclient.nim index 20d9f1b7..f4fa2d57 100644 --- a/chronos/apps/http/httpclient.nim +++ b/chronos/apps/http/httpclient.nim @@ -1073,6 +1073,11 @@ proc finish*(request: HttpClientRequestRef): Future[HttpClientResponseRef] {. ## Finish sending request and receive response. doAssert(not(isNil(request.connection)), "Request missing connection instance") + if request.connection.state in {HttpClientConnectionState.Closing, + HttpClientConnectionState.Closed}: + let e = newHttpUseClosedError() + request.setError(e) + raise e doAssert(request.state == HttpReqRespState.Open, "Request's state is " & $request.state) doAssert(request.connection.state == diff --git a/chronos/apps/http/httpcommon.nim b/chronos/apps/http/httpcommon.nim index d039bf1a..3f01e674 100644 --- a/chronos/apps/http/httpcommon.nim +++ b/chronos/apps/http/httpcommon.nim @@ -53,6 +53,7 @@ type HttpProtocolError* = object of HttpError HttpRedirectError* = object of HttpError HttpAddressError* = object of HttpError + HttpUseClosedError* = object of HttpError KeyValueTuple* = tuple key: string @@ -111,6 +112,9 @@ template newHttpReadError*(message: string): ref HttpReadError = template newHttpWriteError*(message: string): ref HttpWriteError = newException(HttpWriteError, message) +template newHttpUseClosedError*(): ref HttpUseClosedError = + newException(HttpUseClosedError, "Connection was already closed") + iterator queryParams*(query: string, flags: set[QueryParamsFlag] = {}): KeyValueTuple {. raises: [Defect].} =