Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgw: accept data only at the first time in response to a request #8084

Merged
merged 1 commit into from Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/rgw/rgw_rest_client.cc
Expand Up @@ -22,6 +22,22 @@ int RGWRESTSimpleRequest::get_status()
return status;
}

int RGWRESTSimpleRequest::handle_header(const string& name, const string& val)
{
if (name == "CONTENT_LENGTH") {
string err;
long len = strict_strtol(val.c_str(), 10, &err);
if (!err.empty()) {
ldout(cct, 0) << "ERROR: failed converting content length (" << val << ") to int " << dendl;
return -EINVAL;
}

max_response = len;
}

return 0;
}

int RGWRESTSimpleRequest::receive_header(void *ptr, size_t len)
{
char line[len + 1];
Expand Down Expand Up @@ -143,10 +159,14 @@ int RGWRESTSimpleRequest::send_data(void *ptr, size_t len)

int RGWRESTSimpleRequest::receive_data(void *ptr, size_t len)
{
if (response.length() > max_response)
size_t cp_len, left_len;

left_len = max_response > response.length() ? (max_response - response.length()) : 0;
if (left_len == 0)
return 0; /* don't read extra data */

bufferptr p((char *)ptr, len);
cp_len = (len > left_len) ? left_len : len;
bufferptr p((char *)ptr, cp_len);

response.append(p);

Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_rest_client.h
Expand Up @@ -25,7 +25,7 @@ class RGWRESTSimpleRequest : public RGWHTTPClient {
size_t max_response; /* we need this as we don't stream out response */
bufferlist response;

virtual int handle_header(const string& name, const string& val) { return 0; }
virtual int handle_header(const string& name, const string& val);
void append_param(string& dest, const string& name, const string& val);
void get_params_str(map<string, string>& extra_args, string& dest);

Expand Down