Fix request should be closed only at the end. (#10)

* Fix request should be closed only at the end.

* Final fix.
This commit is contained in:
Eugene Kabanov 2021-06-10 20:35:08 +03:00 committed by GitHub
parent 0c8c3a584d
commit 63fcc3df78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -391,16 +391,14 @@ proc requestWithoutBody*(req: HttpClientRequestRef,
raiseRestRedirectionError("Location header with an empty value")
else:
raiseRestRedirectionError("Location header missing")
discard await response.consumeBody()
await request.closeWait()
request = nil
discard await response.consumeBody()
await response.closeWait()
response = nil
request = redirect
redirect = nil
else:
await request.closeWait()
request = nil
let res =
block:
let status = response.status
@ -413,6 +411,8 @@ proc requestWithoutBody*(req: HttpClientRequestRef,
default
else:
await response.getBodyBytes()
await request.closeWait()
request = nil
await response.closeWait()
response = nil
debug "Received REST response body from remote server",
@ -487,17 +487,15 @@ proc requestWithBody*(req: HttpClientRequestRef, pbytes: pointer,
raiseRestRedirectionError("Location header with an empty value")
else:
raiseRestRedirectionError("Location header missing")
await request.closeWait()
request = nil
# We do not care about response body in redirection.
discard await response.consumeBody()
await request.closeWait()
request = nil
await response.closeWait()
response = nil
request = redirect
redirect = nil
else:
await request.closeWait()
request = nil
let res =
block:
let status = response.status
@ -510,6 +508,8 @@ proc requestWithBody*(req: HttpClientRequestRef, pbytes: pointer,
default
else:
await response.getBodyBytes()
await request.closeWait()
request = nil
await response.closeWait()
response = nil
debug "Received REST response body from remote server",