| 37 | |
| 38 | Y_UNIT_TEST_SUITE(THttpParser) { |
| 39 | Y_UNIT_TEST(TParsingToEof) { |
| 40 | { |
| 41 | THttpParser p(THttpParser::Request); |
| 42 | UNIT_ASSERT(!Parse(p, "GET ")); |
| 43 | UNIT_ASSERT(!Parse(p, "/test/test?text=123 HTTP/1.0\r")); |
| 44 | UNIT_ASSERT(!Parse(p, "\nHost: yabs.yandex.ru")); |
| 45 | UNIT_ASSERT(!Parse(p, "\r\nAccept-eNcoding: *\r\n")); |
| 46 | UNIT_ASSERT(!Parse(p, "Accept-eNcoding:\r\n")); |
| 47 | UNIT_ASSERT(!Parse(p, "Accept-eNcoding: , ,\r\n")); |
| 48 | UNIT_ASSERT(Parse(p, "\r\n")); |
| 49 | |
| 50 | UNIT_ASSERT_VALUES_EQUAL(p.IsKeepAlive(), false); |
| 51 | UNIT_ASSERT_VALUES_EQUAL(p.GetBestCompressionScheme(), "gzip"); |
| 52 | THashSet<TString> acceptedEncodings = {"*"}; |
| 53 | UNIT_ASSERT_VALUES_EQUAL(p.AcceptedEncodings(), acceptedEncodings); |
| 54 | ui64 cl; |
| 55 | UNIT_ASSERT_VALUES_EQUAL(p.GetContentLength(cl), false); |
| 56 | } |
| 57 | { |
| 58 | THttpParser p(THttpParser::Request); |
| 59 | UNIT_ASSERT(!Parse(p, "GET")); |
| 60 | UNIT_ASSERT(!Parse(p, " /test/test?text=123 HTTP/1.1\r")); |
| 61 | UNIT_ASSERT(!Parse(p, "\nHost: yabs.yandex.ru")); |
| 62 | UNIT_ASSERT(!Parse(p, "\r\nAccept-eNcoding: yyy123\r\n")); |
| 63 | UNIT_ASSERT(!Parse(p, "Accept-eNcoding: aaa\r\n")); |
| 64 | UNIT_ASSERT(!Parse(p, "Accept-eNcoding: y-LZQ, y-Lzo , bbb\r\n")); |
| 65 | UNIT_ASSERT(!Parse(p, "accept-encoding:ccc\r\n")); |
| 66 | UNIT_ASSERT(Parse(p, "\r\n")); |
| 67 | |
| 68 | UNIT_ASSERT_VALUES_EQUAL(p.IsKeepAlive(), true); |
| 69 | UNIT_ASSERT_VALUES_EQUAL(p.GetBestCompressionScheme(), "y-lzo"); |
| 70 | THashSet<TString> acceptedEncodings = {"yyy123", "aaa", "y-lzq", "y-lzo", "bbb", "ccc"}; |
| 71 | UNIT_ASSERT_VALUES_EQUAL(p.AcceptedEncodings(), acceptedEncodings); |
| 72 | ui64 cl; |
| 73 | UNIT_ASSERT_VALUES_EQUAL(p.GetContentLength(cl), false); |
| 74 | } |
| 75 | { |
| 76 | THttpParser p(THttpParser::Request); |
| 77 | UNIT_ASSERT(!Parse(p, "GET /")); |
| 78 | UNIT_ASSERT(!Parse(p, "test/test?text=123 HTTP/1.")); |
| 79 | UNIT_ASSERT(Parse(p, "0\r\nHost: yabs.yandex.ru\r\n\r\n")); |
| 80 | |
| 81 | UNIT_ASSERT_VALUES_EQUAL(p.IsKeepAlive(), false); |
| 82 | UNIT_ASSERT_VALUES_EQUAL(p.GetBestCompressionScheme(), ""); |
| 83 | ui64 cl; |
| 84 | UNIT_ASSERT_VALUES_EQUAL(p.GetContentLength(cl), false); |
| 85 | } |
| 86 | { |
| 87 | THttpParser p; |
| 88 | UNIT_ASSERT(!Parse(p, "HT")); |
| 89 | UNIT_ASSERT(!Parse(p, "TP/1.0 200 OK\r")); |
| 90 | UNIT_ASSERT(!Parse(p, "\nContent-Type: text/plain; charset=utf-8\r\n" |
| 91 | "\r\n")); |
| 92 | UNIT_ASSERT(Parse(p, "")); |
| 93 | |
| 94 | UNIT_ASSERT_VALUES_EQUAL(p.RetCode(), 200u); |
| 95 | UNIT_ASSERT_VALUES_EQUAL(p.IsKeepAlive(), false); |
| 96 | ui64 cl; |
nothing calls this directly
no test coverage detected