nghttpx: Update Alt-Svc header field spec to alt-svc-04

This commit is contained in:
Tatsuhiro Tsujikawa 2014-10-28 00:17:32 +09:00
parent f381b13c91
commit 7fa0f2763e
6 changed files with 40 additions and 2 deletions

View File

@ -120,6 +120,8 @@ int main(int argc, char* argv[])
shrpx::test_util_to_base64) || shrpx::test_util_to_base64) ||
!CU_add_test(pSuite, "util_percent_encode_token", !CU_add_test(pSuite, "util_percent_encode_token",
shrpx::test_util_percent_encode_token) || shrpx::test_util_percent_encode_token) ||
!CU_add_test(pSuite, "util_quote_string",
shrpx::test_util_quote_string) ||
!CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) || !CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) ||
!CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate)) { !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate)) {
CU_cleanup_registry(); CU_cleanup_registry();

View File

@ -820,9 +820,11 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
for(auto& altsvc : get_config()->altsvcs) { for(auto& altsvc : get_config()->altsvcs) {
hdrs += util::percent_encode_token(altsvc.protocol_id); hdrs += util::percent_encode_token(altsvc.protocol_id);
hdrs += "="; hdrs += "=\"";
hdrs += util::quote_string(std::string(altsvc.host, altsvc.host_len));
hdrs += ":";
hdrs += util::utos(altsvc.port); hdrs += util::utos(altsvc.port);
hdrs += ", "; hdrs += "\", ";
} }
hdrs[hdrs.size() - 2] = '\r'; hdrs[hdrs.size() - 2] = '\r';

View File

@ -141,6 +141,28 @@ std::string percentDecode
return result; return result;
} }
std::string quote_string(const std::string& target)
{
auto cnt = std::count(std::begin(target), std::end(target), '"');
if(cnt == 0) {
return target;
}
std::string res;
res.reserve(target.size() + cnt);
for(auto c : target) {
if(c == '"') {
res += "\\\"";
} else {
res += c;
}
}
return res;
}
std::string http_date(time_t t) std::string http_date(time_t t)
{ {
char buf[32]; char buf[32];

View File

@ -202,6 +202,10 @@ std::string percentDecode
// Percent encode |target| if character is not in token or '%'. // Percent encode |target| if character is not in token or '%'.
std::string percent_encode_token(const std::string& target); std::string percent_encode_token(const std::string& target);
// Returns quotedString version of |target|. Currently, this function
// just replace '"' with '\"'.
std::string quote_string(const std::string& target);
std::string format_hex(const unsigned char *s, size_t len); std::string format_hex(const unsigned char *s, size_t len);
std::string http_date(time_t t); std::string http_date(time_t t);

View File

@ -101,6 +101,13 @@ void test_util_percent_encode_token(void)
CU_ASSERT("http%202" == util::percent_encode_token("http 2")); CU_ASSERT("http%202" == util::percent_encode_token("http 2"));
} }
void test_util_quote_string(void)
{
CU_ASSERT("alpha" == util::quote_string("alpha"));
CU_ASSERT("" == util::quote_string(""));
CU_ASSERT("\\\"alpha\\\"" == util::quote_string("\"alpha\""));
}
void test_util_utox(void) void test_util_utox(void)
{ {
CU_ASSERT("0" == util::utox(0)); CU_ASSERT("0" == util::utox(0));

View File

@ -32,6 +32,7 @@ void test_util_strieq(void);
void test_util_inp_strlower(void); void test_util_inp_strlower(void);
void test_util_to_base64(void); void test_util_to_base64(void);
void test_util_percent_encode_token(void); void test_util_percent_encode_token(void);
void test_util_quote_string(void);
void test_util_utox(void); void test_util_utox(void);
} // namespace shrpx } // namespace shrpx