diff options
author | brinit <brinit@yandex-team.ru> | 2022-02-10 16:49:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:49 +0300 |
commit | 7107d44a6a6d3cd0a7ea831aa0027b2840b17365 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/http | |
parent | 580b68df0905c121b598e4a9e426a6d8ef4b1078 (diff) | |
download | ydb-7107d44a6a6d3cd0a7ea831aa0027b2840b17365.tar.gz |
Restoring authorship annotation for <brinit@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/http')
-rw-r--r-- | library/cpp/http/fetch/httpfsm.h | 8 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpfsm.rl6 | 76 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpfsm_ut.cpp | 80 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpheader.h | 4 |
4 files changed, 84 insertions, 84 deletions
diff --git a/library/cpp/http/fetch/httpfsm.h b/library/cpp/http/fetch/httpfsm.h index be9c2fba4e..c4abdcd0d2 100644 --- a/library/cpp/http/fetch/httpfsm.h +++ b/library/cpp/http/fetch/httpfsm.h @@ -27,8 +27,8 @@ struct THttpHeaderParser { int ret = Init((THttpBaseHeader*)(h)); hd = h; hd->Init(); - hreflangpos = hd->hreflangs; - hreflangspace = HREFLANG_MAX; + hreflangpos = hd->hreflangs; + hreflangspace = HREFLANG_MAX; return ret; } @@ -54,10 +54,10 @@ struct THttpHeaderParser { const unsigned char* langstart; size_t langlen; - + char* hreflangpos; size_t hreflangspace; - + bool AcceptingXRobots; THttpAuthHeader* auth_hd; diff --git a/library/cpp/http/fetch/httpfsm.rl6 b/library/cpp/http/fetch/httpfsm.rl6 index e3966fba5f..eab0328b18 100644 --- a/library/cpp/http/fetch/httpfsm.rl6 +++ b/library/cpp/http/fetch/httpfsm.rl6 @@ -6,7 +6,7 @@ #include <library/cpp/http/misc/httpcodes.h> #include <util/datetime/base.h> #include <util/generic/ylimits.h> -#include <algorithm> // max +#include <algorithm> // max #include <library/cpp/http/fetch/httpheader.h> #include <library/cpp/http/fetch/httpfsm.h> @@ -47,7 +47,7 @@ alphtype unsigned char; eol = '\r'? '\n'; ws = [ \t]; lw = '\r'? '\n'? ws; -separator = [()<>@,;:\\"/\[\]?={}]; +separator = [()<>@,;:\\"/\[\]?={}]; token_char = [!-~] - separator; # http tokens chars url_char = [!-~] - ["<>\[\]\\^`{}|]; # uric chars text_char = ws | 33..126 | 128..255; @@ -264,7 +264,7 @@ loc_url = any_text_char+ >clear_buf $update_buf; location = "location"i def loc_url eoh %set_location; refresh = "refresh"i def int ';' lws "url="i loc_url eoh %set_location; -################# x-robots-tag ################ +################# x-robots-tag ################ action set_x_robots { if (hd && AcceptingXRobots) { if (I > 0) @@ -275,8 +275,8 @@ action set_x_robots { if (abs(pos) & (1 << i)) // permissive flags take priority hd->x_robots_state[i] = (I < 0) ? '1' : (hd->x_robots_state[i] != '1') ? '0' : '1'; } -} - +} + action accept_x_robots { AcceptingXRobots = (bool)I; } @@ -287,7 +287,7 @@ x_robots_directive = "none"i %{c(3)} | "all"i %{c(-3)} | "noarchive"i %{c(4)} | "archive"i %{c(-4)} | "noyaca"i %{c(16)} | "noodp"i %{c(8)}; - + any_value = (any_text_char - [, \t])+ (lws (any_text_char - [, \t])+)*; any_key = (any_text_char - [:, \t])+ (lws (any_text_char - [:, \t])+)*; @@ -301,47 +301,47 @@ x_robots_value = (robot_specifier def %accept_x_robots)? (unavailable_after_dire x_robots_tag = "x-robots-tag"i def >{ AcceptingXRobots = true; } x_robots_value (lws ',' lws x_robots_value)* eoh; -################# rel_canonical ############### -action set_canonical { +################# rel_canonical ############### +action set_canonical { if (hd && buflen < FETCHER_URL_MAX) { hd->rel_canonical = TStringBuf(buf, buflen); - } -} - -rel_canonical = "link"i def '<' url ">;"i lws "rel"i lws '=' lws "\"canonical\"" eoh %set_canonical; -################# hreflang ############### -action set_hreflang { + } +} + +rel_canonical = "link"i def '<' url ">;"i lws "rel"i lws '=' lws "\"canonical\"" eoh %set_canonical; +################# hreflang ############### +action set_hreflang { bool first = (hreflangpos == hd->hreflangs); size_t len2 = (first ? 0 : 1) + langlen + 1 + buflen; if (langlen && len2 < hreflangspace) { if (!first) { *(hreflangpos++) = '\t'; } - memcpy(hreflangpos, langstart, langlen); - hreflangpos += langlen; - *(hreflangpos++) = ' '; - memcpy(hreflangpos, buf, buflen); - hreflangpos += buflen; + memcpy(hreflangpos, langstart, langlen); + hreflangpos += langlen; + *(hreflangpos++) = ' '; + memcpy(hreflangpos, buf, buflen); + hreflangpos += buflen; *(hreflangpos) = 0; hreflangspace -= len2; - } -} - -action start_lang { - langstart = fpc; - langlen = 0; -} -action end_lang { - langlen = fpc - langstart; -} + } +} + +action start_lang { + langstart = fpc; + langlen = 0; +} +action end_lang { + langlen = fpc - langstart; +} hreflang_token = (token_char - ['])+; -quote = ['"]?; #" +quote = ['"]?; #" lang = hreflang_token >start_lang %end_lang; - -hreflang = "link"i def '<' url '>' lws ";" lws - ( ( "rel"i lws '=' lws quote "alternate" quote lws ';' lws "hreflang"i lws '=' lws quote lang quote ) - | ( "hreflang"i lws '=' lws quote lang quote lws ';' lws "rel"i lws '=' lws quote "alternate" quote ) ) - eoh %set_hreflang; + +hreflang = "link"i def '<' url '>' lws ";" lws + ( ( "rel"i lws '=' lws quote "alternate" quote lws ';' lws "hreflang"i lws '=' lws quote lang quote ) + | ( "hreflang"i lws '=' lws quote lang quote lws ';' lws "rel"i lws '=' lws quote "alternate" quote ) ) + eoh %set_hreflang; ################# squid_error ################# action set_squid_error { hd->squid_error = 1; @@ -577,9 +577,9 @@ response_header = message_header $0 | auth @1 | accept_ranges @1 | location @1 - | x_robots_tag @1 - | rel_canonical @1 - | hreflang @1 + | x_robots_tag @1 + | rel_canonical @1 + | hreflang @1 | squid_error @1 | retry_after_withdate @1 | retry_after_withdelta @1; diff --git a/library/cpp/http/fetch/httpfsm_ut.cpp b/library/cpp/http/fetch/httpfsm_ut.cpp index 5cb3d9e5e9..b018e80101 100644 --- a/library/cpp/http/fetch/httpfsm_ut.cpp +++ b/library/cpp/http/fetch/httpfsm_ut.cpp @@ -57,8 +57,8 @@ public: void TestXRobotsTagOverridePriority(); void TestXRobotsTagDoesNotBreakCharset(); void TestXRobotsTagAllowsMultiline(); - void TestRelCanonical(); - void TestHreflang(); + void TestRelCanonical(); + void TestHreflang(); void TestHreflangOnLongInput(); void TestMimeType(); void TestRepeatedContentEncoding(); @@ -232,20 +232,20 @@ void THttpHeaderParserTestSuite::TestLastModifiedCorrupted() { } void THttpHeaderParserTestSuite::TestXRobotsTagUnknownTags() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); const char* headers = - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" "x-robots-tag: asdfasdf asdf asdf,,, , noindex,noodpXXX , NOFOLLOW ,noodpnofollow\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 3); UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "00xxx"); - TestFinish(); -} - + TestFinish(); +} + void THttpHeaderParserTestSuite::TestXRobotsTagMyBot() { TestStart(); THttpHeader httpHeader; @@ -380,24 +380,24 @@ void THttpHeaderParserTestSuite::TestXRobotsTagAllowsMultiline() { TestFinish(); } -void THttpHeaderParserTestSuite::TestHreflang() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); +void THttpHeaderParserTestSuite::TestHreflang() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); const char* headers = - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "link: <http://www.high.ru/>; rel='alternate'; hreflang='x-default'\r\n" - "link: <http://www.high.ru/en.html> ;rel = 'alternate' ;hreflang = en_GB \r\n" - "link: <http://www.high.ru/ru.html>;hreflang = ru_RU.KOI8-r ;rel = 'alternate' \r\n" - "\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_VALUES_EQUAL(result, 2); - // UNIT_ASSERT_VALUES_EQUAL(strcmp(httpHeader.hreflangs, "x-default http://www.high.ru/;"), 0); + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "link: <http://www.high.ru/>; rel='alternate'; hreflang='x-default'\r\n" + "link: <http://www.high.ru/en.html> ;rel = 'alternate' ;hreflang = en_GB \r\n" + "link: <http://www.high.ru/ru.html>;hreflang = ru_RU.KOI8-r ;rel = 'alternate' \r\n" + "\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_VALUES_EQUAL(result, 2); + // UNIT_ASSERT_VALUES_EQUAL(strcmp(httpHeader.hreflangs, "x-default http://www.high.ru/;"), 0); UNIT_ASSERT_VALUES_EQUAL(httpHeader.hreflangs, "x-default http://www.high.ru/\ten_GB http://www.high.ru/en.html\tru_RU.KOI8-r http://www.high.ru/ru.html"); - TestFinish(); -} - + TestFinish(); +} + void THttpHeaderParserTestSuite::TestHreflangOnLongInput() { TestStart(); THttpHeader httpHeader; @@ -410,20 +410,20 @@ void THttpHeaderParserTestSuite::TestHreflangOnLongInput() { TestFinish(); } -void THttpHeaderParserTestSuite::TestRelCanonical() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); +void THttpHeaderParserTestSuite::TestRelCanonical() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); const char* headers = - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "Link: <http://yandex.ru>; rel = \"canonical\"\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "Link: <http://yandex.ru>; rel = \"canonical\"\r\n\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); UNIT_ASSERT_EQUAL(httpHeader.rel_canonical, "http://yandex.ru"); - TestFinish(); -} - + TestFinish(); +} + void THttpHeaderParserTestSuite::TestResponseHeaderOnRequest() { TestStart(); THttpHeader httpHeader; diff --git a/library/cpp/http/fetch/httpheader.h b/library/cpp/http/fetch/httpheader.h index 237395fee0..b2810bbd41 100644 --- a/library/cpp/http/fetch/httpheader.h +++ b/library/cpp/http/fetch/httpheader.h @@ -145,11 +145,11 @@ public: THttpBaseHeader::Init(); accept_ranges = -1; squid_error = 0; - x_robots_tag = 0; + x_robots_tag = 0; rel_canonical.clear(); http_status = -1; location.clear(); - hreflangs[0] = 0; + hreflangs[0] = 0; retry_after = DEFAULT_RETRY_AFTER; x_robots_state = "xxxxx"; } |