From b36a414157b311ad4caa2e0374c660e9f4181f5f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 17 Jan 2021 23:49:15 +0100 Subject: hyper: deliver data to application with Curl_client_write ... just as the native code path does. Avoids sending too large data chunks in the callback and more. Reported-by: Gisle Vanem Fixes #6462 --- lib/c-hyper.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/c-hyper.c b/lib/c-hyper.c index 4a68ffba0..ca977fbd2 100644 --- a/lib/c-hyper.c +++ b/lib/c-hyper.c @@ -120,12 +120,9 @@ static int hyper_each_header(void *userdata, size_t value_len) { struct Curl_easy *data = (struct Curl_easy *)userdata; - size_t wrote; size_t len; char *headp; CURLcode result; - curl_write_callback writeheader = - data->set.fwrite_header? data->set.fwrite_header: data->set.fwrite_func; Curl_dyn_reset(&data->state.headerb); if(name_len) { if(Curl_dyn_addf(&data->state.headerb, "%.*s: %.*s\r\n", @@ -147,10 +144,8 @@ static int hyper_each_header(void *userdata, Curl_debug(data, CURLINFO_HEADER_IN, headp, len); - Curl_set_in_callback(data, true); - wrote = writeheader(headp, 1, len, data->set.writeheader); - Curl_set_in_callback(data, false); - if(wrote != len) { + result = Curl_client_write(data->conn, CLIENTWRITE_HEADER, headp, len); + if(result) { data->state.hresult = CURLE_ABORTED_BY_CALLBACK; return HYPER_ITER_BREAK; } @@ -165,13 +160,12 @@ static int hyper_body_chunk(void *userdata, const hyper_buf *chunk) char *buf = (char *)hyper_buf_bytes(chunk); size_t len = hyper_buf_len(chunk); struct Curl_easy *data = (struct Curl_easy *)userdata; - curl_write_callback writebody = data->set.fwrite_func; struct SingleRequest *k = &data->req; - size_t wrote; + CURLcode result; if(0 == k->bodywrites++) { bool done = FALSE; - CURLcode result = Curl_http_firstwrite(data, data->conn, &done); + result = Curl_http_firstwrite(data, data->conn, &done); if(result || done) { infof(data, "Return early from hyper_body_chunk\n"); data->state.hresult = result; @@ -181,12 +175,10 @@ static int hyper_body_chunk(void *userdata, const hyper_buf *chunk) if(k->ignorebody) return HYPER_ITER_CONTINUE; Curl_debug(data, CURLINFO_DATA_IN, buf, len); - Curl_set_in_callback(data, true); - wrote = writebody(buf, 1, len, data->set.out); - Curl_set_in_callback(data, false); + result = Curl_client_write(data->conn, CLIENTWRITE_BODY, buf, len); - if(wrote != len) { - data->state.hresult = CURLE_WRITE_ERROR; + if(result) { + data->state.hresult = result; return HYPER_ITER_BREAK; } -- cgit v1.2.1