Skip to content

Commit

Permalink
rgw: accept data only at the first time in response to a request
Browse files Browse the repository at this point in the history
Because the member "max_response" in class "RGWRESTSimpleRequest" is
initialized 0, data packages cannot be accepted when the function
"receive_data()" is called again.

This patch initialize the value of "max_response" to "content-length".

Signed-off-by: sunspot <sunspot0105@gmail.com>
  • Loading branch information
sunfch committed Mar 14, 2016
1 parent e530ade commit 1d82b4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 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,13 @@ int RGWRESTSimpleRequest::send_data(void *ptr, size_t len)

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

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

bufferptr p((char *)ptr, 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

0 comments on commit 1d82b4c

Please sign in to comment.