From 4bf3cb2cc020cf4bd2a8efcb5c4bf3a44a9e180f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 12 Feb 2017 23:27:38 +0900 Subject: [PATCH] Revert "nghttpx: Don't capitalize h1 header fields" This reverts commit f9946649345ee4500292531a6eb0f62474131f5d. --- src/http2.cc | 13 ++++++++++++- src/http2.h | 2 ++ src/http2_test.cc | 18 +++++++++--------- src/shrpx_https_upstream.cc | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/http2.cc b/src/http2.cc index 89605192..04dfb7ad 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -238,6 +238,17 @@ StringRef stringify_status(BlockAllocator &balloc, unsigned int status_code) { } } +void capitalize(DefaultMemchunks *buf, const StringRef &s) { + buf->append(util::upcase(s[0])); + for (size_t i = 1; i < s.size(); ++i) { + if (s[i - 1] == '-') { + buf->append(util::upcase(s[i])); + } else { + buf->append(s[i]); + } + } +} + bool lws(const char *value) { for (; *value; ++value) { switch (*value) { @@ -406,7 +417,7 @@ void build_http1_headers_from_headers(DefaultMemchunks *buf, case HD_X_FORWARDED_PROTO: continue; } - buf->append(kv.name); + capitalize(buf, kv.name); buf->append(": "); buf->append(kv.value); buf->append("\r\n"); diff --git a/src/http2.h b/src/http2.h index dffe5bbb..9859930b 100644 --- a/src/http2.h +++ b/src/http2.h @@ -101,6 +101,8 @@ StringRef get_reason_phrase(unsigned int status_code); // Returns string version of |status_code|. (e.g., "404") StringRef stringify_status(BlockAllocator &balloc, unsigned int status_code); +void capitalize(DefaultMemchunks *buf, const StringRef &s); + // Returns true if |value| is LWS bool lws(const char *value); diff --git a/src/http2_test.cc b/src/http2_test.cc index a7fbf7c2..d2be6230 100644 --- a/src/http2_test.cc +++ b/src/http2_test.cc @@ -187,15 +187,15 @@ void test_http2_build_http1_headers_from_headers(void) { DefaultMemchunks buf(&pool); http2::build_http1_headers_from_headers(&buf, headers); auto hdrs = std::string(buf.head->pos, buf.head->last); - CU_ASSERT("alpha: 0\r\n" - "bravo: 1\r\n" - "delta: 4\r\n" - "expect: 5\r\n" - "foxtrot: 6\r\n" - "tango: 7\r\n" - "te: 8\r\n" - "te: 9\r\n" - "zulu: 12\r\n" == hdrs); + CU_ASSERT("Alpha: 0\r\n" + "Bravo: 1\r\n" + "Delta: 4\r\n" + "Expect: 5\r\n" + "Foxtrot: 6\r\n" + "Tango: 7\r\n" + "Te: 8\r\n" + "Te: 9\r\n" + "Zulu: 12\r\n" == hdrs); } void test_http2_lws(void) { diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 932de5a0..55a9e70d 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -896,7 +896,7 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body, if (kv.name.empty() || kv.name[0] == ':') { continue; } - output->append(kv.name); + http2::capitalize(output, kv.name); output->append(": "); output->append(kv.value); output->append("\r\n");