Revert "nghttpx: Don't capitalize h1 header fields"

This reverts commit f994664934.
This commit is contained in:
Tatsuhiro Tsujikawa 2017-02-12 23:27:38 +09:00
parent c78528d54b
commit 4bf3cb2cc0
4 changed files with 24 additions and 11 deletions

View File

@ -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) { bool lws(const char *value) {
for (; *value; ++value) { for (; *value; ++value) {
switch (*value) { switch (*value) {
@ -406,7 +417,7 @@ void build_http1_headers_from_headers(DefaultMemchunks *buf,
case HD_X_FORWARDED_PROTO: case HD_X_FORWARDED_PROTO:
continue; continue;
} }
buf->append(kv.name); capitalize(buf, kv.name);
buf->append(": "); buf->append(": ");
buf->append(kv.value); buf->append(kv.value);
buf->append("\r\n"); buf->append("\r\n");

View File

@ -101,6 +101,8 @@ StringRef get_reason_phrase(unsigned int status_code);
// Returns string version of |status_code|. (e.g., "404") // Returns string version of |status_code|. (e.g., "404")
StringRef stringify_status(BlockAllocator &balloc, unsigned int status_code); StringRef stringify_status(BlockAllocator &balloc, unsigned int status_code);
void capitalize(DefaultMemchunks *buf, const StringRef &s);
// Returns true if |value| is LWS // Returns true if |value| is LWS
bool lws(const char *value); bool lws(const char *value);

View File

@ -187,15 +187,15 @@ void test_http2_build_http1_headers_from_headers(void) {
DefaultMemchunks buf(&pool); DefaultMemchunks buf(&pool);
http2::build_http1_headers_from_headers(&buf, headers); http2::build_http1_headers_from_headers(&buf, headers);
auto hdrs = std::string(buf.head->pos, buf.head->last); auto hdrs = std::string(buf.head->pos, buf.head->last);
CU_ASSERT("alpha: 0\r\n" CU_ASSERT("Alpha: 0\r\n"
"bravo: 1\r\n" "Bravo: 1\r\n"
"delta: 4\r\n" "Delta: 4\r\n"
"expect: 5\r\n" "Expect: 5\r\n"
"foxtrot: 6\r\n" "Foxtrot: 6\r\n"
"tango: 7\r\n" "Tango: 7\r\n"
"te: 8\r\n" "Te: 8\r\n"
"te: 9\r\n" "Te: 9\r\n"
"zulu: 12\r\n" == hdrs); "Zulu: 12\r\n" == hdrs);
} }
void test_http2_lws(void) { void test_http2_lws(void) {

View File

@ -896,7 +896,7 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body,
if (kv.name.empty() || kv.name[0] == ':') { if (kv.name.empty() || kv.name[0] == ':') {
continue; continue;
} }
output->append(kv.name); http2::capitalize(output, kv.name);
output->append(": "); output->append(": ");
output->append(kv.value); output->append(kv.value);
output->append("\r\n"); output->append("\r\n");