From 6eb2829ee8b5cdb1b43d20fd46cfa197c0ecc325 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 3 Nov 2016 22:25:15 +0900 Subject: [PATCH] nghttpx: Strip content-length with 204 or 200 to CONNECT in mruby --- src/shrpx_mruby_module_response.cc | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/shrpx_mruby_module_response.cc b/src/shrpx_mruby_module_response.cc index da3dd45b..e0f96427 100644 --- a/src/shrpx_mruby_module_response.cc +++ b/src/shrpx_mruby_module_response.cc @@ -190,6 +190,7 @@ namespace { mrb_value response_return(mrb_state *mrb, mrb_value self) { auto data = static_cast(mrb->ud); auto downstream = data->downstream; + auto &req = downstream->request(); auto &resp = downstream->response(); int rv; @@ -215,16 +216,28 @@ mrb_value response_return(mrb_state *mrb, mrb_value self) { bodylen = vallen; } - auto content_length = util::make_string_ref_uint(balloc, bodylen); - auto cl = resp.fs.header(http2::HD_CONTENT_LENGTH); - if (cl) { - cl->value = content_length; + + if (resp.http_status == 204 || + (resp.http_status == 200 && req.method == HTTP_CONNECT)) { + if (cl) { + // Delete content-length here + cl->name = StringRef{}; + } + + resp.fs.content_length = -1; } else { - resp.fs.add_header_token(StringRef::from_lit("content-length"), - content_length, false, http2::HD_CONTENT_LENGTH); + auto content_length = util::make_string_ref_uint(balloc, vallen); + + if (cl) { + cl->value = content_length; + } else { + resp.fs.add_header_token(StringRef::from_lit("content-length"), + content_length, false, http2::HD_CONTENT_LENGTH); + } + + resp.fs.content_length = vallen; } - resp.fs.content_length = bodylen; auto date = resp.fs.header(http2::HD_DATE); if (!date) {