Skip to content

Commit

Permalink
lib-http: client: Record last status code in the request object.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and villesavolainen committed Mar 12, 2018
1 parent 6d1afbe commit 187dd20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib-http/http-client-private.h
Expand Up @@ -97,7 +97,9 @@ struct http_client_request {
struct http_client_queue *queue;
struct http_client_peer *peer;
struct http_client_connection *conn;

struct event *event;
unsigned int last_status;

string_t *headers;
time_t date;
Expand Down
9 changes: 9 additions & 0 deletions src/lib-http/http-client-request.c
Expand Up @@ -818,6 +818,7 @@ static void http_client_request_do_submit(struct http_client_request *req)

host = http_client_host_get(client, req->host_url);
req->state = HTTP_REQUEST_STATE_QUEUED;
req->last_status = 0;

http_client_host_submit_request(host, req);
}
Expand Down Expand Up @@ -1311,6 +1312,7 @@ bool http_client_request_callback(struct http_client_request *req,
unsigned int orig_attempts = req->attempts;

req->state = HTTP_REQUEST_STATE_GOT_RESPONSE;
req->last_status = response->status;

req->callback = NULL;
if (callback != NULL) {
Expand Down Expand Up @@ -1403,7 +1405,9 @@ void http_client_request_error(struct http_client_request **_req,

i_assert(req->delayed_error_status == 0);
i_assert(req->state < HTTP_REQUEST_STATE_FINISHED);

req->state = HTTP_REQUEST_STATE_ABORTED;
req->last_status = status;

if (req->queue != NULL)
http_client_queue_drop_request(req->queue, req);
Expand Down Expand Up @@ -1435,6 +1439,8 @@ void http_client_request_abort(struct http_client_request **_req)

req->callback = NULL;
req->state = HTTP_REQUEST_STATE_ABORTED;
if (req->last_status == 0)
req->last_status = HTTP_CLIENT_REQUEST_ERROR_ABORTED;

/* release payload early (prevents server/client deadlock in proxy) */
if (!sending && req->payload_input != NULL)
Expand Down Expand Up @@ -1483,6 +1489,8 @@ void http_client_request_redirect(struct http_client_request *req,
i_assert(req->client != NULL);
i_assert(!req->payload_wait);

req->last_status = status;

/* parse URL */
if (http_url_parse(location, NULL, 0,
pool_datastack_create(), &url, &error) < 0) {
Expand Down Expand Up @@ -1585,6 +1593,7 @@ void http_client_request_resubmit(struct http_client_request *req)
req->peer = NULL;
req->state = HTTP_REQUEST_STATE_QUEUED;
req->redirects = 0;
req->last_status = 0;
http_client_host_submit_request(req->host, req);
}

Expand Down

0 comments on commit 187dd20

Please sign in to comment.