microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.96k stars 1.65k forks source link

Retry a http request without getting request body data purged #1674

Open qiucwang opened 2 years ago

qiucwang commented 2 years ago

We are using cpprestsdk to compose and send http requests to other services. We applied a retry logic to it in form of

for (int current_retry = 0; current_retry <= _max_retries; current_retry++)
{
        const web::http::http_response& response = _client->request(args...).get();
}

The args... gave us the flexibility as web::http::client::http_client::request() supports multiple parameter sets so that we can use one function to send our requests to all the different services.

Previously, we are calling request(method, path_query, body) to one of the services and cpprestsdk will wrap them into a http_request struct in each retry. That works.

But now we need to add headers to our request. It forces us to wrap all the paraments to a http_request struct for the args... we passed to cpprestsdk, since web::http::client::http_client::request() does not support header key and value inputs. And our problem is, once the request body data has been loaded to the http_request struct, looks like it can be used only once and once the request is sent, the data will be purged as this issue points out. So for each following retry request, the request body in the request struct appears to be null.

Does cpprestsdk support any methods to keep the request data for next retry requests, or accept header inputs for the request calls?