diff options
author | Daehee <hello@daehee.com> | 2021-01-22 07:04:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 15:04:52 +0100 |
commit | 2d0cb18b9f092fad54abefed475218ae92fc846c (patch) | |
tree | 1b6fadeff534eaab8a41cf429520ef50609c07d4 /lib | |
parent | bebfbaa439194a15a9630d0e86ed677dde27c372 (diff) | |
download | Nim-2d0cb18b9f092fad54abefed475218ae92fc846c.tar.gz |
Fix SIGSEGV in httpclient response body (#16766)
* initialize httpclient response bodyStream; prevent SIGSEGV when getBody is false * Update lib/pure/httpclient.nim * Update lib/pure/httpclient.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/httpclient.nim | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index bcd10803e..0ca3ca97b 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -832,14 +832,16 @@ proc parseResponse(client: HttpClient | AsyncHttpClient, if not fullyRead: httpError("Connection was closed before full request has been made") + when client is HttpClient: + result.bodyStream = newStringStream() + else: + result.bodyStream = newFutureStream[string]("parseResponse") + if getBody and result.code != Http204: + client.bodyStream = result.bodyStream when client is HttpClient: - client.bodyStream = newStringStream() - result.bodyStream = client.bodyStream parseBody(client, result.headers, result.version) else: - client.bodyStream = newFutureStream[string]("parseResponse") - result.bodyStream = client.bodyStream assert(client.parseBodyFut.isNil or client.parseBodyFut.finished) # do not wait here for the body request to complete client.parseBodyFut = parseBody(client, result.headers, result.version) |