From 9e723b6b1d7abb4ee4fd5d3fb9cdd4a5b3a06bd3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 8 Feb 2015 17:29:38 +0900 Subject: [PATCH] src: Rename LinkHeader.url as LinkHeader.uri --- src/http2.cc | 2 +- src/http2.h | 3 ++- src/http2_test.cc | 34 +++++++++++++++++----------------- src/shrpx_http2_upstream.cc | 4 ++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/http2.cc b/src/http2.cc index 8bbc7d33..e492b759 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -876,7 +876,7 @@ std::vector parse_link_header(const char *src, size_t len) { for (; first != last;) { auto rv = parse_next_link_header_once(first, last); first = rv.second; - if (rv.first.url.first != 0 || rv.first.url.second != 0) { + if (rv.first.uri.first != 0 || rv.first.uri.second != 0) { res.push_back(rv.first); } } diff --git a/src/http2.h b/src/http2.h index 26f0a154..fcd2c420 100644 --- a/src/http2.h +++ b/src/http2.h @@ -258,7 +258,8 @@ const Headers::value_type *get_header(const HeaderIndex &hdidx, int16_t token, const Headers &nva); struct LinkHeader { - std::pair url; + // The region of URI is [uri.first, uri.second). + std::pair uri; }; // Returns next URI-reference in Link header field value |src| of diff --git a/src/http2_test.cc b/src/http2_test.cc index 30db434f..2c2ffcd7 100644 --- a/src/http2_test.cc +++ b/src/http2_test.cc @@ -309,21 +309,21 @@ void test_http2_parse_link_header(void) { const char s[] = "; rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // With extra link-param. URI url should be extracted const char s[] = "; rel=preload; as=file"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // With extra link-param. URI url should be extracted const char s[] = "; as=file; rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // With extra link-param and quote-string. URI url should be @@ -331,7 +331,7 @@ void test_http2_parse_link_header(void) { const char s[] = R"(; rel=preload; title="foo,bar")"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // With extra link-param and quote-string. URI url should be @@ -339,36 +339,36 @@ void test_http2_parse_link_header(void) { const char s[] = R"(; title="foo,bar"; rel=preload)"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // ',' after quote-string const char s[] = R"(; title="foo,bar", ; rel=preload)"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[25], &s[28]) == res[0].url); + CU_ASSERT(std::make_pair(&s[25], &s[28]) == res[0].uri); } { // Only first URI should be extracted. const char s[] = "; rel=preload, "; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // Both have rel=preload, so both urls should be extracted const char s[] = "; rel=preload, ; rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(2 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); - CU_ASSERT(std::make_pair(&s[21], &s[24]) == res[1].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); + CU_ASSERT(std::make_pair(&s[21], &s[24]) == res[1].uri); } { // Second URI uri should be extracted. const char s[] = ", ;rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[8], &s[11]) == res[0].url); + CU_ASSERT(std::make_pair(&s[8], &s[11]) == res[0].uri); } { // Error if input ends with ';' @@ -381,14 +381,14 @@ void test_http2_parse_link_header(void) { const char s[] = ";rel=preload,"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // Multiple repeated ','s between fields is OK const char s[] = ",,,;rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[9], &s[12]) == res[0].url); + CU_ASSERT(std::make_pair(&s[9], &s[12]) == res[0].uri); } { // Error if url is not enclosed by <> @@ -431,22 +431,22 @@ void test_http2_parse_link_header(void) { const char s[] = ";as=file;rel=preload,;rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(2 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); - CU_ASSERT(std::make_pair(&s[27], &s[30]) == res[1].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); + CU_ASSERT(std::make_pair(&s[27], &s[30]) == res[1].uri); } { // link-extension may have no value const char s[] = "; as; rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // ext-name-star const char s[] = "; foo*=bar; rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].url); + CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri); } { // '*' is not allowed expect for trailing one @@ -477,7 +477,7 @@ void test_http2_parse_link_header(void) { const char s[] = " ; rel=preload"; auto res = http2::parse_link_header(s, sizeof(s) - 1); CU_ASSERT(1 == res.size()); - CU_ASSERT(std::make_pair(&s[3], &s[6]) == res[0].url); + CU_ASSERT(std::make_pair(&s[3], &s[6]) == res[0].uri); } } diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 1f9a1aa9..64d10697 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1538,8 +1538,8 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) { } for (auto &link : http2::parse_link_header(kv.value.c_str(), kv.value.size())) { - auto link_url = link.url.first; - auto link_urllen = link.url.second - link.url.first; + auto link_url = link.uri.first; + auto link_urllen = link.uri.second - link.uri.first; const char *rel; size_t rellen;