Message ID | 20200914145712.4989-5-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | [01/14] channel_curl: Make setting request_body symmetric | expand |
On 14.09.20 16:57, Christian Storm wrote: > Make channel_post_method() use the factored out log and > buffer functions like channel_get() does. > With the latter, channel_post_method() may return the server's > reply body to the caller instead of curl logging it to console. > > Also respect nocheckanswer. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > corelib/channel_curl.c | 21 ++++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c > index 4737037..40c8c60 100644 > --- a/corelib/channel_curl.c > +++ b/corelib/channel_curl.c > @@ -790,6 +790,8 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) > > channel_op_res_t result = CHANNEL_OK; > channel_data_t *channel_data = (channel_data_t *)data; > + output_data_t outdata = {}; > + write_callback_t wrdata = { .channel_data = channel_data, .outdata = &outdata }; > > if ((result = channel_set_content_type(this, channel_data)) != > CHANNEL_OK) { > @@ -803,6 +805,10 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) > goto cleanup_header; > } > > + if ((result = setup_reply_buffer(channel_curl->handle, &wrdata)) != CHANNEL_OK) { > + goto cleanup_header; > + } > + > if ((curl_easy_setopt(channel_curl->handle, CURLOPT_POST, 1L) != CURLE_OK) || > (curl_easy_setopt(channel_curl->handle, CURLOPT_POSTFIELDS, > channel_data->request_body) != CURLE_OK)) { > @@ -825,17 +831,18 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) > channel_log_effective_url(this); > > result = channel_map_http_code(this, &channel_data->http_response_code); > - if (result != CHANNEL_OK) { > - ERROR("Channel operation returned HTTP error code %ld.", > - channel_data->http_response_code); > + > + if (channel_data->nocheckanswer) > goto cleanup_header; > - } > - if (channel_data->debug) { > - TRACE("Channel put operation returned HTTP status code %ld.", > - channel_data->http_response_code); > + > + channel_log_reply(result, channel_data, &outdata); > + > + if (result == CHANNEL_OK) { > + result = parse_reply(channel_data, &outdata); > } > > cleanup_header: > + outdata.memory != NULL ? free(outdata.memory) : (void)0; > curl_easy_reset(channel_curl->handle); > curl_slist_free_all(channel_curl->header); > channel_curl->header = NULL; > Reviewed-by: Stefano Babic <ababic@denx.de> Best regards, Stefano Babic
diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 4737037..40c8c60 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -790,6 +790,8 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) channel_op_res_t result = CHANNEL_OK; channel_data_t *channel_data = (channel_data_t *)data; + output_data_t outdata = {}; + write_callback_t wrdata = { .channel_data = channel_data, .outdata = &outdata }; if ((result = channel_set_content_type(this, channel_data)) != CHANNEL_OK) { @@ -803,6 +805,10 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) goto cleanup_header; } + if ((result = setup_reply_buffer(channel_curl->handle, &wrdata)) != CHANNEL_OK) { + goto cleanup_header; + } + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_POST, 1L) != CURLE_OK) || (curl_easy_setopt(channel_curl->handle, CURLOPT_POSTFIELDS, channel_data->request_body) != CURLE_OK)) { @@ -825,17 +831,18 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) channel_log_effective_url(this); result = channel_map_http_code(this, &channel_data->http_response_code); - if (result != CHANNEL_OK) { - ERROR("Channel operation returned HTTP error code %ld.", - channel_data->http_response_code); + + if (channel_data->nocheckanswer) goto cleanup_header; - } - if (channel_data->debug) { - TRACE("Channel put operation returned HTTP status code %ld.", - channel_data->http_response_code); + + channel_log_reply(result, channel_data, &outdata); + + if (result == CHANNEL_OK) { + result = parse_reply(channel_data, &outdata); } cleanup_header: + outdata.memory != NULL ? free(outdata.memory) : (void)0; curl_easy_reset(channel_curl->handle); curl_slist_free_all(channel_curl->header); channel_curl->header = NULL;
Make channel_post_method() use the factored out log and buffer functions like channel_get() does. With the latter, channel_post_method() may return the server's reply body to the caller instead of curl logging it to console. Also respect nocheckanswer. Signed-off-by: Christian Storm <christian.storm@siemens.com> --- corelib/channel_curl.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)