Skip to content

Commit

Permalink
lib-http: client: Implemented means to set request payload buffer rat…
Browse files Browse the repository at this point in the history
…her than an input stream.

This is not purely a convenience function: there have been bugs caused by allocating a data input stream from a datastack buffer.
With this function, the buffer is copied to the request pool, so that it is durably allocated while the request exists.
This prevents futher mishaps. The server already has an equivalent function for its response object.
  • Loading branch information
stephanbosch committed Apr 20, 2016
1 parent 9e9711e commit 7a13cd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib-http/http-client-request.c
Expand Up @@ -356,6 +356,23 @@ void http_client_request_set_payload(struct http_client_request *req,
req->payload_sync = TRUE;
}

void http_client_request_set_payload_data(struct http_client_request *req,
const unsigned char *data, size_t size)
{
struct istream *input;
unsigned char *payload_data;

if (size == 0)
return;

payload_data = p_malloc(req->pool, size);
memcpy(payload_data, data, size);
input = i_stream_create_from_data(payload_data, size);

http_client_request_set_payload(req, input, FALSE);
i_stream_unref(&input);
}

void http_client_request_set_timeout_msecs(struct http_client_request *req,
unsigned int msecs)
{
Expand Down
2 changes: 2 additions & 0 deletions src/lib-http/http-client.h
Expand Up @@ -204,6 +204,8 @@ void http_client_request_set_date(struct http_client_request *req,

void http_client_request_set_payload(struct http_client_request *req,
struct istream *input, bool sync);
void http_client_request_set_payload_data(struct http_client_request *req,
const unsigned char *data, size_t size);

void http_client_request_set_timeout_msecs(struct http_client_request *req,
unsigned int msecs);
Expand Down

0 comments on commit 7a13cd2

Please sign in to comment.