Skip to content

Commit

Permalink
rgw: Do not send a Content-Length header on status 204
Browse files Browse the repository at this point in the history
RFC7230 says:
  A server MUST NOT send a Content-Length header field in any response with a
  status code of 1xx (Informational) or 204 (No Content).

Fixes: #13582
  • Loading branch information
wido authored and yehudasa committed Dec 18, 2015
1 parent 2340fbd commit 4e5921d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/rgw/rgw_civetweb.cc
Expand Up @@ -45,9 +45,16 @@ int RGWMongoose::complete_request()
{
if (!sent_header) {
if (!has_content_length) {

header_done = false; /* let's go back to writing the header */

if (0 && data.length() == 0) {
/*
* Status 204 should not include a content-length header
* RFC7230 says so
*/
if (status_num == 204) {
has_content_length = true;
} else if (0 && data.length() == 0) {
has_content_length = true;
print("Transfer-Enconding: %s\r\n", "chunked");
data.append("0\r\n\r\n", sizeof("0\r\n\r\n")-1);
Expand Down Expand Up @@ -75,6 +82,8 @@ void RGWMongoose::init_env(CephContext *cct)
{
env.init(cct);
struct mg_request_info *info = mg_get_request_info(conn);
status_num = 0;

if (!info)
return;

Expand Down Expand Up @@ -114,7 +123,7 @@ void RGWMongoose::init_env(CephContext *cct)
*dest = c;
}
*dest = '\0';

env.set(buf, header->value);
}

Expand Down Expand Up @@ -150,7 +159,7 @@ int RGWMongoose::send_status(const char *status, const char *status_name)
bl.append(header_data);
header_data = bl;

int status_num = atoi(status);
status_num = atoi(status);
mg_set_http_status(conn, status_num);

return 0;
Expand Down
1 change: 1 addition & 0 deletions src/rgw/rgw_civetweb.h
Expand Up @@ -19,6 +19,7 @@ class RGWMongoose : public RGWClientIO
bufferlist data;

int port;
int status_num;

bool header_done;
bool sent_header;
Expand Down
10 changes: 9 additions & 1 deletion src/rgw/rgw_fcgi.cc
Expand Up @@ -29,10 +29,12 @@ void RGWFCGX::flush()
void RGWFCGX::init_env(CephContext *cct)
{
env.init(cct, (char **)fcgx->envp);
status_num = 0;
}

int RGWFCGX::send_status(const char *status, const char *status_name)
{
status_num = atoi(status);
return print("Status: %s %s\r\n", status, status_name);
}

Expand All @@ -47,6 +49,13 @@ int RGWFCGX::send_100_continue()

int RGWFCGX::send_content_length(uint64_t len)
{
/*
* Status 204 should not include a content-length header
* RFC7230 says so
*/
if (status_num == 204)
return 0;

char buf[21];
snprintf(buf, sizeof(buf), "%" PRIu64, len);
return print("Content-Length: %s\r\n", buf);
Expand All @@ -56,4 +65,3 @@ int RGWFCGX::complete_header()
{
return print("\r\n");
}

3 changes: 3 additions & 0 deletions src/rgw/rgw_fcgi.h
Expand Up @@ -13,6 +13,9 @@ struct FCGX_Request;
class RGWFCGX : public RGWClientIO
{
FCGX_Request *fcgx;

int status_num;

protected:
void init_env(CephContext *cct);
int write_data(const char *buf, int len);
Expand Down

0 comments on commit 4e5921d

Please sign in to comment.