nghttpx: Strip content-length with 204 or 200 to CONNECT in mruby

This commit is contained in:
Tatsuhiro Tsujikawa 2016-11-03 22:25:15 +09:00
parent 6ad9ddcdea
commit 6eb2829ee8
1 changed files with 20 additions and 7 deletions

View File

@ -190,6 +190,7 @@ namespace {
mrb_value response_return(mrb_state *mrb, mrb_value self) { mrb_value response_return(mrb_state *mrb, mrb_value self) {
auto data = static_cast<MRubyAssocData *>(mrb->ud); auto data = static_cast<MRubyAssocData *>(mrb->ud);
auto downstream = data->downstream; auto downstream = data->downstream;
auto &req = downstream->request();
auto &resp = downstream->response(); auto &resp = downstream->response();
int rv; int rv;
@ -215,16 +216,28 @@ mrb_value response_return(mrb_state *mrb, mrb_value self) {
bodylen = vallen; bodylen = vallen;
} }
auto content_length = util::make_string_ref_uint(balloc, bodylen);
auto cl = resp.fs.header(http2::HD_CONTENT_LENGTH); 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 { } else {
resp.fs.add_header_token(StringRef::from_lit("content-length"), auto content_length = util::make_string_ref_uint(balloc, vallen);
content_length, false, http2::HD_CONTENT_LENGTH);
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); auto date = resp.fs.header(http2::HD_DATE);
if (!date) { if (!date) {