Skip to content

Commit

Permalink
rgw/http: add timeout to http client
Browse files Browse the repository at this point in the history
also, prevent "Expect: 100-continue" from being sent
when not needed

Signed-off-by: Yuval Lifshitz <[email protected]>
  • Loading branch information
yuvalif committed Apr 7, 2020
1 parent 7b20846 commit dd49cc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/rgw/rgw_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct rgw_http_req_data : public RefCountedObject {
}
#endif
std::unique_lock l{lock};
cond.wait(l);
cond.wait(l, [this]{return done==true;});
return ret;
}

Expand Down Expand Up @@ -541,23 +541,33 @@ int RGWHTTPClient::init_request(rgw_http_req_data *_req_data)
curl_easy_setopt(easy_handle, CURLOPT_ERRORBUFFER, (void *)req_data->error_buf);
curl_easy_setopt(easy_handle, CURLOPT_LOW_SPEED_TIME, cct->_conf->rgw_curl_low_speed_time);
curl_easy_setopt(easy_handle, CURLOPT_LOW_SPEED_LIMIT, cct->_conf->rgw_curl_low_speed_limit);
if (h) {
curl_easy_setopt(easy_handle, CURLOPT_HTTPHEADER, (void *)h);
}
curl_easy_setopt(easy_handle, CURLOPT_READFUNCTION, send_http_data);
curl_easy_setopt(easy_handle, CURLOPT_READDATA, (void *)req_data);
if (send_data_hint || is_upload_request(method)) {
curl_easy_setopt(easy_handle, CURLOPT_UPLOAD, 1L);
}
if (has_send_len) {
curl_easy_setopt(easy_handle, CURLOPT_INFILESIZE, (void *)send_len);
// TODO: prevent overflow by using curl_off_t
// and: CURLOPT_INFILESIZE_LARGE, CURLOPT_POSTFIELDSIZE_LARGE
const long size = send_len;
curl_easy_setopt(easy_handle, CURLOPT_INFILESIZE, size);
if (method == "POST") {
curl_easy_setopt(easy_handle, CURLOPT_POSTFIELDSIZE, size);
// TODO: set to size smaller than 1MB should prevent the "Expect" field
// from being sent. So explicit removal is not needed
h = curl_slist_append(h, "Expect:");
}
}
if (h) {
curl_easy_setopt(easy_handle, CURLOPT_HTTPHEADER, (void *)h);
}
if (!verify_ssl) {
curl_easy_setopt(easy_handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(easy_handle, CURLOPT_SSL_VERIFYHOST, 0L);
dout(20) << "ssl verification is set to off" << dendl;
}
curl_easy_setopt(easy_handle, CURLOPT_PRIVATE, (void *)req_data);
curl_easy_setopt(easy_handle, CURLOPT_TIMEOUT, req_timeout);

return 0;
}
Expand Down
8 changes: 8 additions & 0 deletions src/rgw/rgw_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class RGWHTTPClient : public RGWIOProvider

param_vec_t headers;

long req_timeout{0L};

RGWHTTPManager *get_manager();

int init_request(rgw_http_req_data *req_data);
Expand Down Expand Up @@ -136,6 +138,12 @@ class RGWHTTPClient : public RGWIOProvider
verify_ssl = flag;
}

// set request timeout in seconds
// zero (default) mean that request will never timeout
void set_req_timeout(long timeout) {
req_timeout = timeout;
}

int process(optional_yield y);

int wait(optional_yield y);
Expand Down

0 comments on commit dd49cc8

Please sign in to comment.