diff options
| author | ermolovd <[email protected]> | 2022-02-10 16:47:53 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:47:53 +0300 | 
| commit | b91bcef7c99a119b0846479ef71bfab4beec72ca (patch) | |
| tree | be118d54d12a61bc4812ceb0a266a170a2fa3bc9 /library/cpp/http/io | |
| parent | f421873774cf0b71743afbe5f6677861e66601ea (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http/io')
| -rw-r--r-- | library/cpp/http/io/chunk.cpp | 22 | ||||
| -rw-r--r-- | library/cpp/http/io/chunk.h | 10 | ||||
| -rw-r--r-- | library/cpp/http/io/compression.h | 2 | ||||
| -rw-r--r-- | library/cpp/http/io/headers.h | 12 | ||||
| -rw-r--r-- | library/cpp/http/io/stream.cpp | 44 | ||||
| -rw-r--r-- | library/cpp/http/io/stream.h | 20 | ||||
| -rw-r--r-- | library/cpp/http/io/stream_ut.cpp | 140 | 
7 files changed, 125 insertions, 125 deletions
| diff --git a/library/cpp/http/io/chunk.cpp b/library/cpp/http/io/chunk.cpp index 6975d9eac1e..7edd115b75b 100644 --- a/library/cpp/http/io/chunk.cpp +++ b/library/cpp/http/io/chunk.cpp @@ -1,7 +1,7 @@  #include "chunk.h" -#include "headers.h" - +#include "headers.h"  +   #include <util/string/cast.h>  #include <util/generic/utility.h>  #include <util/generic/yexception.h> @@ -52,13 +52,13 @@ class TChunkedInput::TImpl {  public:      inline TImpl(IInputStream* slave, TMaybe<THttpHeaders>* trailers)          : Slave_(slave) -        , Trailers_(trailers) +        , Trailers_(trailers)           , Pending_(0)          , LastChunkReaded_(false)      { -        if (Trailers_) { -            Trailers_->Clear(); -        } +        if (Trailers_) {  +            Trailers_->Clear();  +        }       }      inline ~TImpl() { @@ -127,9 +127,9 @@ private:              return true;          } -        if (Trailers_) { -            Trailers_->ConstructInPlace(Slave_); -        } +        if (Trailers_) {  +            Trailers_->ConstructInPlace(Slave_);  +        }           LastChunkReaded_ = true;          return false; @@ -137,13 +137,13 @@ private:  private:      IInputStream* Slave_; -    TMaybe<THttpHeaders>* Trailers_; +    TMaybe<THttpHeaders>* Trailers_;       size_t Pending_;      bool LastChunkReaded_;  };  TChunkedInput::TChunkedInput(IInputStream* slave, TMaybe<THttpHeaders>* trailers) -    : Impl_(new TImpl(slave, trailers)) +    : Impl_(new TImpl(slave, trailers))   {  } diff --git a/library/cpp/http/io/chunk.h b/library/cpp/http/io/chunk.h index 88d89fafda2..a94b2083db3 100644 --- a/library/cpp/http/io/chunk.h +++ b/library/cpp/http/io/chunk.h @@ -1,11 +1,11 @@  #pragma once  #include <util/stream/output.h> -#include <util/generic/maybe.h> +#include <util/generic/maybe.h>   #include <util/generic/ptr.h> -class THttpHeaders; - +class THttpHeaders;  +   /// @addtogroup Streams_Chunked  /// @{  /// Ввод данных порциями. @@ -13,8 +13,8 @@ class THttpHeaders;  /// данные записаны в виде <длина блока><блок данных>.  class TChunkedInput: public IInputStream {  public: -    /// Если передан указатель на trailers, то туда будут записаны HTTP trailer'ы (возможно пустые), -    /// которые идут после чанков. +    /// Если передан указатель на trailers, то туда будут записаны HTTP trailer'ы (возможно пустые),  +    /// которые идут после чанков.       TChunkedInput(IInputStream* slave, TMaybe<THttpHeaders>* trailers = nullptr);      ~TChunkedInput() override; diff --git a/library/cpp/http/io/compression.h b/library/cpp/http/io/compression.h index f16c4a18ebb..2a603d46349 100644 --- a/library/cpp/http/io/compression.h +++ b/library/cpp/http/io/compression.h @@ -15,7 +15,7 @@ public:      static inline TCompressionCodecFactory& Instance() noexcept {          return *SingletonWithPriority<TCompressionCodecFactory, 0>();      } - +       inline const TDecoderConstructor* FindDecoder(TStringBuf name) const {          if (auto codec = Codecs_.FindPtr(name)) {              return &codec->Decoder; diff --git a/library/cpp/http/io/headers.h b/library/cpp/http/io/headers.h index a71793d1c68..265796f8aa7 100644 --- a/library/cpp/http/io/headers.h +++ b/library/cpp/http/io/headers.h @@ -59,17 +59,17 @@ public:      inline TConstIterator Begin() const noexcept {          return Headers_.begin();      } -    inline TConstIterator begin() const noexcept { -        return Headers_.begin(); -    } +    inline TConstIterator begin() const noexcept {  +        return Headers_.begin();  +    }       /// Стандартный итератор.      inline TConstIterator End() const noexcept {          return Headers_.end();      } -    inline TConstIterator end() const noexcept { -        return Headers_.end(); -    } +    inline TConstIterator end() const noexcept {  +        return Headers_.end();  +    }       /// Возвращает количество заголовков в контейнере.      inline size_t Count() const noexcept { diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp index 6689be684fc..cb3959db277 100644 --- a/library/cpp/http/io/stream.cpp +++ b/library/cpp/http/io/stream.cpp @@ -176,10 +176,10 @@ public:          return Headers_;      } -    inline const TMaybe<THttpHeaders>& Trailers() const noexcept { -        return Trailers_; -    } - +    inline const TMaybe<THttpHeaders>& Trailers() const noexcept {  +        return Trailers_;  +    }  +       inline bool IsKeepAlive() const noexcept {          return KeepAlive_;      } @@ -212,16 +212,16 @@ private:      template <class Operation>      inline size_t Perform(size_t len, const Operation& operation) {          size_t processed = operation(len); -        if (processed == 0 && len > 0) { -            if (!ChunkedInput_) { -                Trailers_.ConstructInPlace(); -            } else { -                // Read the header of the trailing chunk. It remains in -                // the TChunkedInput stream if the HTTP response is compressed. -                char symbol; -                if (ChunkedInput_->Read(&symbol, 1) != 0) { -                    ythrow THttpParseException() << "some data remaining in TChunkedInput"; -                } +        if (processed == 0 && len > 0) {  +            if (!ChunkedInput_) {  +                Trailers_.ConstructInPlace();  +            } else {  +                // Read the header of the trailing chunk. It remains in  +                // the TChunkedInput stream if the HTTP response is compressed.  +                char symbol;  +                if (ChunkedInput_->Read(&symbol, 1) != 0) {  +                    ythrow THttpParseException() << "some data remaining in TChunkedInput";  +                }               }          }          return processed; @@ -337,10 +337,10 @@ private:          }          if (p.Chunked) { -            ChunkedInput_ = Streams_.Add(new TChunkedInput(&Buffered_, &Trailers_)); -            Input_ = ChunkedInput_; +            ChunkedInput_ = Streams_.Add(new TChunkedInput(&Buffered_, &Trailers_));  +            Input_ = ChunkedInput_;           } else { -            // disable buffering +            // disable buffering               Buffered_.Reset(&Cnull);              Input_ = Streams_.Add(new TMultiInput(&Buffered_, Slave_)); @@ -377,7 +377,7 @@ private:      TString FirstLine_;      THttpHeaders Headers_; -    TMaybe<THttpHeaders> Trailers_; +    TMaybe<THttpHeaders> Trailers_;       bool KeepAlive_;      TAcceptCodings Codings_; @@ -411,10 +411,10 @@ const THttpHeaders& THttpInput::Headers() const noexcept {      return Impl_->Headers();  } -const TMaybe<THttpHeaders>& THttpInput::Trailers() const noexcept { -    return Impl_->Trailers(); -} - +const TMaybe<THttpHeaders>& THttpInput::Trailers() const noexcept {  +    return Impl_->Trailers();  +}  +   const TString& THttpInput::FirstLine() const noexcept {      return Impl_->FirstLine();  } diff --git a/library/cpp/http/io/stream.h b/library/cpp/http/io/stream.h index 78ca4fc814c..d2009adb79d 100644 --- a/library/cpp/http/io/stream.h +++ b/library/cpp/http/io/stream.h @@ -3,7 +3,7 @@  #include "headers.h"  #include <util/stream/output.h> -#include <util/generic/maybe.h> +#include <util/generic/maybe.h>   #include <util/generic/ptr.h>  #include <util/generic/string.h>  #include <util/generic/strbuf.h> @@ -35,15 +35,15 @@ public:      const THttpHeaders& Headers() const noexcept;      /* -     * parsed http trailers -     */ -    /// Возвращает контейнер (возможно пустой) с trailer'ами ответа HTTP-сервера. -    /// Поток должен быть вычитан полностью прежде чем trailer'ы будут доступны. -    /// Пока поток не вычитан до конца возвращается Nothing. -    /// https://tools.ietf.org/html/rfc7230#section-4.1.2 -    const TMaybe<THttpHeaders>& Trailers() const noexcept; - -    /* +     * parsed http trailers  +     */  +    /// Возвращает контейнер (возможно пустой) с trailer'ами ответа HTTP-сервера.  +    /// Поток должен быть вычитан полностью прежде чем trailer'ы будут доступны.  +    /// Пока поток не вычитан до конца возвращается Nothing.  +    /// https://tools.ietf.org/html/rfc7230#section-4.1.2  +    const TMaybe<THttpHeaders>& Trailers() const noexcept;  +  +    /*        * first line - response or request       */      /// Возвращает первую строку ответа HTTP-сервера. diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 1ea35df675a..ff27378996e 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -488,82 +488,82 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {      }      Y_UNIT_TEST(HasTrailers) { -        TMemoryInput response( -            "HTTP/1.1 200 OK\r\n" -            "Transfer-Encoding: chunked\r\n" -            "\r\n" -            "3\r\n" -            "foo" -            "0\r\n" -            "Bar: baz\r\n" -            "\r\n"); -        THttpInput i(&response); -        TMaybe<THttpHeaders> trailers = i.Trailers(); -        UNIT_ASSERT(!trailers.Defined()); -        i.ReadAll(); -        trailers = i.Trailers(); -        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Count(), 1); -        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Begin()->ToString(), "Bar: baz"); -    } - +        TMemoryInput response(  +            "HTTP/1.1 200 OK\r\n"  +            "Transfer-Encoding: chunked\r\n"  +            "\r\n"  +            "3\r\n"  +            "foo"  +            "0\r\n"  +            "Bar: baz\r\n"  +            "\r\n");  +        THttpInput i(&response);  +        TMaybe<THttpHeaders> trailers = i.Trailers();  +        UNIT_ASSERT(!trailers.Defined());  +        i.ReadAll();  +        trailers = i.Trailers();  +        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Count(), 1);  +        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Begin()->ToString(), "Bar: baz");  +    }  +       Y_UNIT_TEST(NoTrailersWithChunks) { -        TMemoryInput response( -            "HTTP/1.1 200 OK\r\n" -            "Transfer-Encoding: chunked\r\n" -            "\r\n" -            "3\r\n" -            "foo" -            "0\r\n" -            "\r\n"); -        THttpInput i(&response); -        TMaybe<THttpHeaders> trailers = i.Trailers(); -        UNIT_ASSERT(!trailers.Defined()); -        i.ReadAll(); -        trailers = i.Trailers(); -        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Count(), 0); -    } - +        TMemoryInput response(  +            "HTTP/1.1 200 OK\r\n"  +            "Transfer-Encoding: chunked\r\n"  +            "\r\n"  +            "3\r\n"  +            "foo"  +            "0\r\n"  +            "\r\n");  +        THttpInput i(&response);  +        TMaybe<THttpHeaders> trailers = i.Trailers();  +        UNIT_ASSERT(!trailers.Defined());  +        i.ReadAll();  +        trailers = i.Trailers();  +        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Count(), 0);  +    }  +       Y_UNIT_TEST(NoTrailersNoChunks) { -        TMemoryInput response( -            "HTTP/1.1 200 OK\r\n" -            "Content-Length: 3\r\n" -            "\r\n" -            "bar"); -        THttpInput i(&response); -        TMaybe<THttpHeaders> trailers = i.Trailers(); -        UNIT_ASSERT(!trailers.Defined()); -        i.ReadAll(); -        trailers = i.Trailers(); -        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Count(), 0); -    } - +        TMemoryInput response(  +            "HTTP/1.1 200 OK\r\n"  +            "Content-Length: 3\r\n"  +            "\r\n"  +            "bar");  +        THttpInput i(&response);  +        TMaybe<THttpHeaders> trailers = i.Trailers();  +        UNIT_ASSERT(!trailers.Defined());  +        i.ReadAll();  +        trailers = i.Trailers();  +        UNIT_ASSERT_VALUES_EQUAL(trailers.GetRef().Count(), 0);  +    }  +       Y_UNIT_TEST(RequestWithoutContentLength) { -        TStringStream request; -        { -            THttpOutput httpOutput(&request); +        TStringStream request;  +        {  +            THttpOutput httpOutput(&request);               httpOutput << "POST / HTTP/1.1\r\n"                            "Host: yandex.ru\r\n"                            "\r\n"; -            httpOutput << "GGLOL"; -        } -        { -            TStringInput input(request.Str()); -            THttpInput httpInput(&input); -            bool chunkedOrHasContentLength = false; -            for (const auto& header : httpInput.Headers()) { -                if (header.Name() == "Transfer-Encoding" && header.Value() == "chunked" || header.Name() == "Content-Length") { -                    chunkedOrHasContentLength = true; -                } -            } - -            // If request doesn't contain neither Content-Length header nor Transfer-Encoding header -            // then server considers message body length to be zero. -            // (See https://tools.ietf.org/html/rfc7230#section-3.3.3) -            UNIT_ASSERT(chunkedOrHasContentLength); - -            UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "GGLOL"); -        } -    } +            httpOutput << "GGLOL";  +        }  +        {  +            TStringInput input(request.Str());  +            THttpInput httpInput(&input);  +            bool chunkedOrHasContentLength = false;  +            for (const auto& header : httpInput.Headers()) {  +                if (header.Name() == "Transfer-Encoding" && header.Value() == "chunked" || header.Name() == "Content-Length") {  +                    chunkedOrHasContentLength = true;  +                }  +            }  +  +            // If request doesn't contain neither Content-Length header nor Transfer-Encoding header  +            // then server considers message body length to be zero.  +            // (See https://tools.ietf.org/html/rfc7230#section-3.3.3)  +            UNIT_ASSERT(chunkedOrHasContentLength);  +  +            UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "GGLOL");  +        }  +    }       Y_UNIT_TEST(TestInputHasContent) {          { | 
