diff options
author | vmordovin <vmordovin@yandex-team.ru> | 2022-02-10 16:48:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:14 +0300 |
commit | 7c7f9bbcf57e15838d15afa94b31d8254b5d7776 (patch) | |
tree | 17073f853e6b3a1a95708e8aa0ea12fa42a717e7 /library/cpp/http/io | |
parent | 466f96709329ff77ded50177df94d1893a226c00 (diff) | |
download | ydb-7c7f9bbcf57e15838d15afa94b31d8254b5d7776.tar.gz |
Restoring authorship annotation for <vmordovin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http/io')
-rw-r--r-- | library/cpp/http/io/headers.h | 2 | ||||
-rw-r--r-- | library/cpp/http/io/stream.cpp | 28 | ||||
-rw-r--r-- | library/cpp/http/io/stream.h | 6 | ||||
-rw-r--r-- | library/cpp/http/io/stream_ut.cpp | 100 |
4 files changed, 68 insertions, 68 deletions
diff --git a/library/cpp/http/io/headers.h b/library/cpp/http/io/headers.h index a71793d1c6..1ce789faf9 100644 --- a/library/cpp/http/io/headers.h +++ b/library/cpp/http/io/headers.h @@ -112,7 +112,7 @@ public: /// Записывает все заголовки контейнера в поток. /// @details Каждый заголовк записывается в виде "имя параметра: значение\r\n". void OutTo(IOutputStream* stream) const; - + /// Обменивает наборы заголовков двух контейнеров. void Swap(THttpHeaders& headers) noexcept { Headers_.swap(headers.Headers_); diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp index 6689be684f..2e4c6b3f2e 100644 --- a/library/cpp/http/io/stream.cpp +++ b/library/cpp/http/io/stream.cpp @@ -200,10 +200,10 @@ public: return ContentEncoded_; } - inline bool HasContent() const noexcept { - return HasContentLength_ || ChunkedInput_; - } - + inline bool HasContent() const noexcept { + return HasContentLength_ || ChunkedInput_; + } + inline bool HasExpect100Continue() const noexcept { return Expect100Continue_; } @@ -273,15 +273,15 @@ private: } } - inline bool IsRequest() const { + inline bool IsRequest() const { return strnicmp(FirstLine().data(), "get", 3) == 0 || strnicmp(FirstLine().data(), "post", 4) == 0 || strnicmp(FirstLine().data(), "put", 3) == 0 || strnicmp(FirstLine().data(), "patch", 5) == 0 || strnicmp(FirstLine().data(), "head", 4) == 0 || strnicmp(FirstLine().data(), "delete", 6) == 0; - } - + } + inline void BuildInputChain() { TParsedHeaders p; @@ -344,7 +344,7 @@ private: Buffered_.Reset(&Cnull); Input_ = Streams_.Add(new TMultiInput(&Buffered_, Slave_)); - if (IsRequest() || HasContentLength_) { + if (IsRequest() || HasContentLength_) { /* * TODO - we have other cases */ @@ -448,10 +448,10 @@ bool THttpInput::ContentEncoded() const noexcept { return Impl_->ContentEncoded(); } -bool THttpInput::HasContent() const noexcept { - return Impl_->HasContent(); -} - +bool THttpInput::HasContent() const noexcept { + return Impl_->HasContent(); +} + bool THttpInput::HasExpect100Continue() const noexcept { return Impl_->HasExpect100Continue(); } @@ -663,7 +663,7 @@ private: static inline size_t ParseHttpVersion(const TString& s) { if (s.empty()) { ythrow THttpParseException() << "malformed http stream"; - } + } size_t parsed_version = 0; @@ -804,7 +804,7 @@ private: return ret; } - + inline void RebuildStream() { bool keepAlive = false; const TCompressionCodecFactory::TEncoderConstructor* encoder = nullptr; diff --git a/library/cpp/http/io/stream.h b/library/cpp/http/io/stream.h index 78ca4fc814..a552b36218 100644 --- a/library/cpp/http/io/stream.h +++ b/library/cpp/http/io/stream.h @@ -81,9 +81,9 @@ public: /// показывает объём запакованных данных, а из THttpInput мы будем вычитывать уже распакованные. bool ContentEncoded() const noexcept; - /// Returns true if Content-Length or Transfer-Encoding header received - bool HasContent() const noexcept; - + /// Returns true if Content-Length or Transfer-Encoding header received + bool HasContent() const noexcept; + bool HasExpect100Continue() const noexcept; private: diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 1ea35df675..9737467bfc 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -1,5 +1,5 @@ #include "stream.h" -#include "chunk.h" +#include "chunk.h" #include <library/cpp/http/server/http_ex.h> @@ -331,23 +331,23 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { httpOut.Flush(); UNIT_ASSERT_VALUES_EQUAL(checkStr.size(), str.size()); } - + TString MakeHttpOutputBody(const char* body, bool encodingEnabled) { TString str; TStringOutput strOut(str); { TBufferedOutput bufOut(&strOut, 8192); THttpOutput httpOut(&bufOut); - + httpOut.EnableKeepAlive(true); httpOut.EnableCompression(true); httpOut.EnableBodyEncoding(encodingEnabled); - + httpOut << "POST / HTTP/1.1\r\n"; httpOut << "Host: yandex.ru\r\n"; httpOut << "Content-Encoding: gzip\r\n"; httpOut << "\r\n"; - + UNIT_ASSERT_VALUES_EQUAL(str.size(), 0u); httpOut << body; } @@ -376,29 +376,29 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TString str; TStringOutput strOut(str); TBufferedOutput bufOut(&strOut, 8192); - THttpOutput httpOut(&bufOut); - - httpOut.EnableKeepAlive(true); - httpOut.EnableCompression(true); - + THttpOutput httpOut(&bufOut); + + httpOut.EnableKeepAlive(true); + httpOut.EnableCompression(true); + const char* header = "GET / HTTP/1.1\r\nHost: yandex.ru\r\n\r\n"; httpOut << header; - + unsigned curLen = str.size(); const char* body = "<html>Hello</html>"; - httpOut << body; + httpOut << body; UNIT_ASSERT_VALUES_EQUAL(curLen, str.size()); httpOut.Finish(); UNIT_ASSERT_VALUES_EQUAL(curLen + strlen(body), str.size()); - } - + } + Y_UNIT_TEST(TestMultilineHeaders) { const char* headerLine0 = "HTTP/1.1 200 OK"; const char* headerLine1 = "Content-Language: en"; const char* headerLine2 = "Vary: Accept-Encoding, "; const char* headerLine3 = "\tAccept-Language"; const char* headerLine4 = "Content-Length: 18"; - + TString endLine("\r\n"); TString r; r += headerLine0 + endLine; @@ -564,53 +564,53 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "GGLOL"); } } - + Y_UNIT_TEST(TestInputHasContent) { - { - TStringStream request; + { + TStringStream request; request << "POST / HTTP/1.1\r\n" "Host: yandex.ru\r\n" "\r\n"; - request << "HTTPDATA"; - - TStringInput input(request.Str()); - THttpInput httpInput(&input); - - UNIT_ASSERT(!httpInput.HasContent()); - UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), ""); - } - - { - TStringStream request; + request << "HTTPDATA"; + + TStringInput input(request.Str()); + THttpInput httpInput(&input); + + UNIT_ASSERT(!httpInput.HasContent()); + UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), ""); + } + + { + TStringStream request; request << "POST / HTTP/1.1\r\n" "Host: yandex.ru\r\n" "Content-Length: 8" "\r\n\r\n"; - request << "HTTPDATA"; - - TStringInput input(request.Str()); - THttpInput httpInput(&input); - - UNIT_ASSERT(httpInput.HasContent()); - UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); - } - - { - TStringStream request; + request << "HTTPDATA"; + + TStringInput input(request.Str()); + THttpInput httpInput(&input); + + UNIT_ASSERT(httpInput.HasContent()); + UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); + } + + { + TStringStream request; request << "POST / HTTP/1.1\r\n" "Host: yandex.ru\r\n" "Transfer-Encoding: chunked" "\r\n\r\n"; - request << "8\r\nHTTPDATA\r\n0\r\n"; - - TStringInput input(request.Str()); - THttpInput httpInput(&input); - - UNIT_ASSERT(httpInput.HasContent()); - UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); - } - } - + request << "8\r\nHTTPDATA\r\n0\r\n"; + + TStringInput input(request.Str()); + THttpInput httpInput(&input); + + UNIT_ASSERT(httpInput.HasContent()); + UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); + } + } + Y_UNIT_TEST(TestHttpInputHeadRequest) { class THeadOnlyInput: public IInputStream { public: |