From 5cc92bb27cfbaee4af24dc312c9b98331f899794 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Thu, 9 Apr 2015 20:04:59 +0200 Subject: [PATCH] rgw: shouldn't return content-type: application/xml if content length is 0 Fixed: #11091 Signed-off-by: Orit Wasserman --- src/rgw/rgw_rest.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 93f5b3f0b26c..4dc160a6cecc 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -500,7 +500,9 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type) dump_access_control(s, op); } - if (!content_type || s->err.is_err()) { + /* do not send content type if content length is zero + and the content type was not set by the user */ + if ((s->formatter->get_len() != 0 && !content_type) || s->err.is_err()){ switch (s->format) { case RGW_FORMAT_XML: ctype = "application/xml"; @@ -526,9 +528,13 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type) s->formatter->close_section(); dump_content_length(s, s->formatter->get_len()); } - int r = s->cio->print("Content-type: %s\r\n", content_type); - if (r < 0) { - ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + + int r; + if (content_type) { + r = s->cio->print("Content-type: %s\r\n", content_type); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } } r = s->cio->complete_header(); if (r < 0) { -- 2.47.3