From 919e9eee63a75793806fca378f5ec1e8b6fb800b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 17 Jan 2016 16:34:56 +0900 Subject: [PATCH] nghttpx: It is enough to check "chunked" in the suffix --- src/shrpx_downstream.cc | 4 ++-- src/util.h | 4 ++++ src/util_test.cc | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 6fe16f9e..be97814d 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -662,7 +662,7 @@ void Downstream::inspect_http1_request() { auto transfer_encoding = req_.fs.header(http2::HD_TRANSFER_ENCODING); if (transfer_encoding) { req_.fs.content_length = -1; - if (util::strifind(transfer_encoding->value.c_str(), "chunked")) { + if (util::iends_with_l(transfer_encoding->value, "chunked")) { chunked_request_ = true; } } @@ -672,7 +672,7 @@ void Downstream::inspect_http1_response() { auto transfer_encoding = resp_.fs.header(http2::HD_TRANSFER_ENCODING); if (transfer_encoding) { resp_.fs.content_length = -1; - if (util::strifind(transfer_encoding->value.c_str(), "chunked")) { + if (util::iends_with_l(transfer_encoding->value, "chunked")) { chunked_response_ = true; } } diff --git a/src/util.h b/src/util.h index 67f9c27e..669cc638 100644 --- a/src/util.h +++ b/src/util.h @@ -238,6 +238,10 @@ inline bool iends_with(const std::string &a, const std::string &b) { return iends_with(std::begin(a), std::end(a), std::begin(b), std::end(b)); } +template bool iends_with_l(const std::string &a, const char(&b)[N]) { + return iends_with(std::begin(a), std::end(a), b, b + N - 1); +} + int strcompare(const char *a, const uint8_t *b, size_t n); template bool strieq(const char *a, InputIt b, size_t bn) { diff --git a/src/util_test.cc b/src/util_test.cc index 0667b7a1..97a35c4e 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -374,6 +374,9 @@ void test_util_ends_with(void) { CU_ASSERT(util::iends_with("foo", "")); CU_ASSERT(util::iends_with("oFoo", "fOO")); CU_ASSERT(!util::iends_with("ofoo", "fo")); + + CU_ASSERT(util::iends_with_l("oFoo", "fOO")); + CU_ASSERT(!util::iends_with_l("ofoo", "fo")); } void test_util_parse_http_date(void) {