From 21e1af2ae7616e4f63928431bb4b28e29ae8cc79 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 5 Sep 2015 01:18:18 +0900 Subject: [PATCH] nghttpx: Delete replaced header fields --- src/shrpx_mruby_module_request.cc | 12 +++++++++--- src/shrpx_mruby_module_response.cc | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/shrpx_mruby_module_request.cc b/src/shrpx_mruby_module_request.cc index 0b8ead0a..74dad27a 100644 --- a/src/shrpx_mruby_module_request.cc +++ b/src/shrpx_mruby_module_request.cc @@ -208,13 +208,19 @@ mrb_value request_mod_header(mrb_state *mrb, mrb_value self, bool repl) { key = mrb_funcall(mrb, key, "downcase", 0); if (repl) { - // making name empty will effectively delete header fields - for (auto &hd : downstream->get_request_headers()) { + size_t p = 0; + auto &headers = downstream->get_request_headers(); + for (size_t i = 0; i < headers.size(); ++i) { + auto &hd = headers[i]; if (util::streq(std::begin(hd.name), hd.name.size(), RSTRING_PTR(key), RSTRING_LEN(key))) { - hd.name = ""; + continue; + } + if (i != p) { + headers[p++] = std::move(hd); } } + headers.resize(p); } if (mrb_obj_is_instance_of(mrb, values, mrb->array_class)) { diff --git a/src/shrpx_mruby_module_response.cc b/src/shrpx_mruby_module_response.cc index 55a8d702..0b49e925 100644 --- a/src/shrpx_mruby_module_response.cc +++ b/src/shrpx_mruby_module_response.cc @@ -112,13 +112,19 @@ mrb_value response_mod_header(mrb_state *mrb, mrb_value self, bool repl) { key = mrb_funcall(mrb, key, "downcase", 0); if (repl) { - // making name empty will effectively delete header fields - for (auto &hd : downstream->get_response_headers()) { + size_t p = 0; + auto &headers = downstream->get_response_headers(); + for (size_t i = 0; i < headers.size(); ++i) { + auto &hd = headers[i]; if (util::streq(std::begin(hd.name), hd.name.size(), RSTRING_PTR(key), RSTRING_LEN(key))) { - hd.name = ""; + continue; + } + if (i != p) { + headers[p++] = std::move(hd); } } + headers.resize(p); } if (mrb_obj_is_instance_of(mrb, values, mrb->array_class)) {