From: Wido den Hollander Date: Wed, 11 Nov 2015 18:01:15 +0000 (+0100) Subject: rgw: Do not send a Content-Length header on status 204 X-Git-Tag: v0.94.8~30^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ceb8e19096f7d4ef35ed3ad8fad508aecbfa78ef;p=ceph.git rgw: Do not send a Content-Length header on status 204 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 Signed-off-by: Wido den Hollander (cherry picked from commit 4e5921dbc7d1c51feb4cc5c03aa59a432742765e) --- diff --git a/src/rgw/rgw_civetweb.cc b/src/rgw/rgw_civetweb.cc index 5c075f98a0e7..2ae3b799166e 100644 --- a/src/rgw/rgw_civetweb.cc +++ b/src/rgw/rgw_civetweb.cc @@ -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); @@ -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; @@ -114,7 +123,7 @@ void RGWMongoose::init_env(CephContext *cct) *dest = c; } *dest = '\0'; - + env.set(buf, header->value); } @@ -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; diff --git a/src/rgw/rgw_civetweb.h b/src/rgw/rgw_civetweb.h index 1cee5c8b59f0..8a1b4af27d24 100644 --- a/src/rgw/rgw_civetweb.h +++ b/src/rgw/rgw_civetweb.h @@ -19,6 +19,7 @@ class RGWMongoose : public RGWClientIO bufferlist data; int port; + int status_num; bool header_done; bool sent_header; diff --git a/src/rgw/rgw_fcgi.cc b/src/rgw/rgw_fcgi.cc index 0006834b4497..b526dddf30dc 100644 --- a/src/rgw/rgw_fcgi.cc +++ b/src/rgw/rgw_fcgi.cc @@ -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); } @@ -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); @@ -56,4 +65,3 @@ int RGWFCGX::complete_header() { return print("\r\n"); } - diff --git a/src/rgw/rgw_fcgi.h b/src/rgw/rgw_fcgi.h index 8fc96fce1839..a798425ec117 100644 --- a/src/rgw/rgw_fcgi.h +++ b/src/rgw/rgw_fcgi.h @@ -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);