diff options
| author | Arseny Smalyuk <[email protected]> | 2022-02-10 16:48:05 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:48:05 +0300 | 
| commit | 5f8a2ce7b1dc3b3e1fae197610f189e7ed1d5723 (patch) | |
| tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp | |
| parent | 12559cd7f2fa0cf54ffb0d961949fea58c0e18cb (diff) | |
Restoring authorship annotation for Arseny Smalyuk <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/coroutine/engine/callbacks.h | 14 | ||||
| -rw-r--r-- | library/cpp/coroutine/engine/coroutine_ut.cpp | 6 | ||||
| -rw-r--r-- | library/cpp/coroutine/engine/impl.cpp | 58 | ||||
| -rw-r--r-- | library/cpp/coroutine/engine/impl.h | 10 | ||||
| -rw-r--r-- | library/cpp/coroutine/engine/network.cpp | 2 | ||||
| -rw-r--r-- | library/cpp/coroutine/engine/poller.cpp | 34 | ||||
| -rw-r--r-- | library/cpp/http/io/compression.cpp | 62 | ||||
| -rw-r--r-- | library/cpp/http/io/compression.h | 62 | ||||
| -rw-r--r-- | library/cpp/http/io/compression_ut.cpp | 44 | ||||
| -rw-r--r-- | library/cpp/http/io/stream.cpp | 84 | ||||
| -rw-r--r-- | library/cpp/http/io/stream.h | 22 | ||||
| -rw-r--r-- | library/cpp/http/io/stream_ut.cpp | 54 | ||||
| -rw-r--r-- | library/cpp/http/io/ut/ya.make | 4 | ||||
| -rw-r--r-- | library/cpp/http/io/ya.make | 4 | 
14 files changed, 230 insertions, 230 deletions
diff --git a/library/cpp/coroutine/engine/callbacks.h b/library/cpp/coroutine/engine/callbacks.h index e578ae2b35e..e81b17344f5 100644 --- a/library/cpp/coroutine/engine/callbacks.h +++ b/library/cpp/coroutine/engine/callbacks.h @@ -6,13 +6,13 @@ class TContExecutor;  namespace NCoro {      class IScheduleCallback {      public: -        virtual void OnSchedule(TContExecutor&, TCont&) = 0;  -        virtual void OnUnschedule(TContExecutor&) = 0;  -    };  +        virtual void OnSchedule(TContExecutor&, TCont&) = 0; +        virtual void OnUnschedule(TContExecutor&) = 0; +    }; -    class IEnterPollerCallback {  -    public:  -        virtual void OnEnterPoller() = 0;  -        virtual void OnExitPoller() = 0;  +    class IEnterPollerCallback { +    public: +        virtual void OnEnterPoller() = 0; +        virtual void OnExitPoller() = 0;      };  } diff --git a/library/cpp/coroutine/engine/coroutine_ut.cpp b/library/cpp/coroutine/engine/coroutine_ut.cpp index 8daec28f149..8b372496a2e 100644 --- a/library/cpp/coroutine/engine/coroutine_ut.cpp +++ b/library/cpp/coroutine/engine/coroutine_ut.cpp @@ -36,7 +36,7 @@ class TCoroTest: public TTestBase {  //    UNIT_TEST(TestFastPathWakeEpoll)      UNIT_TEST(TestFastPathWakeKqueue)      UNIT_TEST(TestFastPathWakePoll) -    UNIT_TEST(TestFastPathWakeSelect)  +    UNIT_TEST(TestFastPathWakeSelect)      UNIT_TEST(TestLegacyCancelYieldRaceBug)      UNIT_TEST(TestJoinRescheduleBug);      UNIT_TEST(TestEventQueue) @@ -943,7 +943,7 @@ void TCoroTest::TestPollEngines() {  }  void TCoroTest::TestPause() { -    TContExecutor executor{1024*1024, IPollerFace::Default(), nullptr, nullptr, NCoro::NStack::EGuard::Canary, Nothing()};  +    TContExecutor executor{1024*1024, IPollerFace::Default(), nullptr, nullptr, NCoro::NStack::EGuard::Canary, Nothing()};      int i = 0;      executor.CreateOwned([&](TCont*) { @@ -993,7 +993,7 @@ void TCoroTest::TestOverrideTime() {      };      TTime time; -    TContExecutor executor{1024*1024, IPollerFace::Default(), nullptr, nullptr, NCoro::NStack::EGuard::Canary, Nothing(), &time};  +    TContExecutor executor{1024*1024, IPollerFace::Default(), nullptr, nullptr, NCoro::NStack::EGuard::Canary, Nothing(), &time};      executor.CreateOwned([&](TCont* cont) {          UNIT_ASSERT_EQUAL(cont->Executor()->Now(), TInstant::Zero()); diff --git a/library/cpp/coroutine/engine/impl.cpp b/library/cpp/coroutine/engine/impl.cpp index 578d06498b6..7ae6f74051e 100644 --- a/library/cpp/coroutine/engine/impl.cpp +++ b/library/cpp/coroutine/engine/impl.cpp @@ -119,14 +119,14 @@ void TCont::ReSchedule() noexcept {  TContExecutor::TContExecutor(      uint32_t defaultStackSize,      THolder<IPollerFace> poller, -    NCoro::IScheduleCallback* scheduleCallback,  -    NCoro::IEnterPollerCallback* enterPollerCallback,  +    NCoro::IScheduleCallback* scheduleCallback, +    NCoro::IEnterPollerCallback* enterPollerCallback,      NCoro::NStack::EGuard defaultGuard,      TMaybe<NCoro::NStack::TPoolAllocatorSettings> poolSettings,      NCoro::ITime* time  ) -    : ScheduleCallback_(scheduleCallback)  -    , EnterPollerCallback_(enterPollerCallback)  +    : ScheduleCallback_(scheduleCallback) +    , EnterPollerCallback_(enterPollerCallback)      , DefaultStackSize_(defaultStackSize)      , Poller_(std::move(poller))      , Time_(time) @@ -171,21 +171,21 @@ void TContExecutor::WaitForIO() {          //      to prevent ourselves from locking out of io by constantly waking coroutines.          if (ReadyNext_.Empty()) { -            if (EnterPollerCallback_) {  -                EnterPollerCallback_->OnEnterPoller();  -            }  +            if (EnterPollerCallback_) { +                EnterPollerCallback_->OnEnterPoller(); +            }              Poll(next); -            if (EnterPollerCallback_) {  -                EnterPollerCallback_->OnExitPoller();  -            }  +            if (EnterPollerCallback_) { +                EnterPollerCallback_->OnExitPoller(); +            }          } else if (LastPoll_ + TDuration::MilliSeconds(5) < now) { -            if (EnterPollerCallback_) {  -                EnterPollerCallback_->OnEnterPoller();  -            }  +            if (EnterPollerCallback_) { +                EnterPollerCallback_->OnEnterPoller(); +            }              Poll(now); -            if (EnterPollerCallback_) {  -                EnterPollerCallback_->OnExitPoller();  -            }  +            if (EnterPollerCallback_) { +                EnterPollerCallback_->OnExitPoller(); +            }          }          Ready_.Append(ReadyNext_); @@ -296,8 +296,8 @@ TCont* RunningCont() {      return thisThreadExecutor ? thisThreadExecutor->Running() : nullptr;  } -void TContExecutor::RunScheduler() noexcept {  -    try {  +void TContExecutor::RunScheduler() noexcept { +    try {          TContExecutor* const prev = ThisThreadExecutor();          ThisThreadExecutor() = this;          TCont* caller = Current_; @@ -306,27 +306,27 @@ void TContExecutor::RunScheduler() noexcept {              ThisThreadExecutor() = prev;          }; -        while (true) {  -            if (ScheduleCallback_ && Current_) {  -                ScheduleCallback_->OnUnschedule(*this);  +        while (true) { +            if (ScheduleCallback_ && Current_) { +                ScheduleCallback_->OnUnschedule(*this);              }              WaitForIO();              DeleteScheduled(); -            Ready_.Append(ReadyNext_);  +            Ready_.Append(ReadyNext_); -            if (Ready_.Empty()) {  +            if (Ready_.Empty()) {                  Current_ = nullptr;                  if (caller) {                      context->SwitchTo(&SchedContext_);                  } -                break;  -            }  +                break; +            }              TCont* cont = Ready_.PopFront(); -            if (ScheduleCallback_) {  -                ScheduleCallback_->OnSchedule(*this, *cont);  +            if (ScheduleCallback_) { +                ScheduleCallback_->OnSchedule(*this, *cont);              }              Current_ = cont; @@ -343,8 +343,8 @@ void TContExecutor::RunScheduler() noexcept {              if (caller) {                  break;              } -        }  -    } catch (...) {  +        } +    } catch (...) {          TBackTrace::FromCurrentException().PrintTo(Cerr);          Y_FAIL("Uncaught exception in the scheduler: %s", CurrentExceptionMessage().c_str());      } diff --git a/library/cpp/coroutine/engine/impl.h b/library/cpp/coroutine/engine/impl.h index 0b892749a07..283a96ecf11 100644 --- a/library/cpp/coroutine/engine/impl.h +++ b/library/cpp/coroutine/engine/impl.h @@ -1,6 +1,6 @@  #pragma once -#include "callbacks.h"  +#include "callbacks.h"  #include "cont_poller.h"  #include "iostatus.h"  #include "poller.h" @@ -154,7 +154,7 @@ public:          uint32_t defaultStackSize,          THolder<IPollerFace> poller = IPollerFace::Default(),          NCoro::IScheduleCallback* = nullptr, -        NCoro::IEnterPollerCallback* = nullptr,  +        NCoro::IEnterPollerCallback* = nullptr,          NCoro::NStack::EGuard stackGuard = NCoro::NStack::EGuard::Canary,          TMaybe<NCoro::NStack::TPoolAllocatorSettings> poolSettings = Nothing(),          NCoro::ITime* time = nullptr @@ -273,7 +273,7 @@ private:      void Exit(TCont* cont) noexcept; -    void RunScheduler() noexcept;  +    void RunScheduler() noexcept;      void ScheduleToDelete(TCont* cont) noexcept; @@ -288,8 +288,8 @@ private:      void Poll(TInstant deadline);  private: -    NCoro::IScheduleCallback* const ScheduleCallback_ = nullptr;  -    NCoro::IEnterPollerCallback* const EnterPollerCallback_ = nullptr;  +    NCoro::IScheduleCallback* const ScheduleCallback_ = nullptr; +    NCoro::IEnterPollerCallback* const EnterPollerCallback_ = nullptr;      const uint32_t DefaultStackSize_;      THolder<NCoro::NStack::IAllocator> StackAllocator_; diff --git a/library/cpp/coroutine/engine/network.cpp b/library/cpp/coroutine/engine/network.cpp index 6315532d3f8..85b647d2105 100644 --- a/library/cpp/coroutine/engine/network.cpp +++ b/library/cpp/coroutine/engine/network.cpp @@ -295,7 +295,7 @@ namespace NCoro {              if (!IsBlocked(err)) {                  return -err; -            }  +            }              err = PollD(cont, s, CONT_POLL_READ, deadline); diff --git a/library/cpp/coroutine/engine/poller.cpp b/library/cpp/coroutine/engine/poller.cpp index 8aeff4e9659..61164fa56bf 100644 --- a/library/cpp/coroutine/engine/poller.cpp +++ b/library/cpp/coroutine/engine/poller.cpp @@ -88,8 +88,8 @@ namespace {          void Wait(TEvents& events, TInstant deadLine) {              const size_t ret = P_.WaitD(~E_, +E_, deadLine); -            events.reserve(ret);  -  +            events.reserve(ret); +              for (size_t i = 0; i < ret; ++i) {                  const TInternalEvent* ie = ~E_ + i; @@ -199,12 +199,12 @@ namespace {              ret |= POLLOUT;          } -#if defined(_linux_)  -        if (flags & CONT_POLL_RDHUP) {  -            ret |= POLLRDHUP;  -        }  -#endif  -  +#if defined(_linux_) +        if (flags & CONT_POLL_RDHUP) { +            ret |= POLLRDHUP; +        } +#endif +          return ret;      } @@ -248,12 +248,12 @@ namespace {              const ssize_t ret = PollD(T_.data(), (nfds_t) T_.size(), deadLine); -            if (ret <= 0) {  +            if (ret <= 0) {                  return;              }              events.reserve(T_.size()); -  +              for (size_t i = 0; i < T_.size(); ++i) {                  const pollfd& pfd = T_[i];                  const short ev = pfd.revents; @@ -274,12 +274,12 @@ namespace {                      filter |= CONT_POLL_WRITE;                  } -#if defined(_linux_)  -                if (ev & POLLRDHUP) {  -                    filter |= CONT_POLL_RDHUP;  -                }  -#endif  -  +#if defined(_linux_) +                if (ev & POLLRDHUP) { +                    filter |= CONT_POLL_RDHUP; +                } +#endif +                  if (ev & POLLERR) {                      status = EIO;                  } else if (ev & POLLHUP && pfd.events & POLLOUT) { @@ -290,7 +290,7 @@ namespace {                  }                  if (status) { -                    filter = CONT_POLL_READ | CONT_POLL_WRITE | CONT_POLL_RDHUP;  +                    filter = CONT_POLL_READ | CONT_POLL_WRITE | CONT_POLL_RDHUP;                  }                  const TEvent res = { diff --git a/library/cpp/http/io/compression.cpp b/library/cpp/http/io/compression.cpp index a4578813f42..8fa1f62ae69 100644 --- a/library/cpp/http/io/compression.cpp +++ b/library/cpp/http/io/compression.cpp @@ -1,4 +1,4 @@ -#include "compression.h"  +#include "compression.h"  #if defined(ENABLE_GPL)  #include <library/cpp/streams/lz/lz.h> @@ -14,53 +14,53 @@  #include <util/stream/zlib.h> -TCompressionCodecFactory::TCompressionCodecFactory() {  -    auto gzip = [](auto s) {  -        return MakeHolder<TZLibDecompress>(s);  +TCompressionCodecFactory::TCompressionCodecFactory() { +    auto gzip = [](auto s) { +        return MakeHolder<TZLibDecompress>(s);      }; -    Add("gzip", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::GZip); });  -    Add("deflate", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::ZLib); });  -    Add("br", [](auto s) { return MakeHolder<TBrotliDecompress>(s); }, [](auto s) { return MakeHolder<TBrotliCompress>(s, 4); });  -    Add("x-gzip", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::GZip); });  -    Add("x-deflate", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::ZLib); });  +    Add("gzip", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::GZip); }); +    Add("deflate", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::ZLib); }); +    Add("br", [](auto s) { return MakeHolder<TBrotliDecompress>(s); }, [](auto s) { return MakeHolder<TBrotliCompress>(s, 4); }); +    Add("x-gzip", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::GZip); }); +    Add("x-deflate", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::ZLib); });  #if defined(ENABLE_GPL) -    const ui16 bs = 32 * 1024;  +    const ui16 bs = 32 * 1024; -    Add("y-lzo", [](auto s) { return MakeHolder<TLzoDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzoCompress> >(s, bs); });  -    Add("y-lzf", [](auto s) { return MakeHolder<TLzfDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzfCompress> >(s, bs); });  -    Add("y-lzq", [](auto s) { return MakeHolder<TLzqDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzqCompress> >(s, bs); });  +    Add("y-lzo", [](auto s) { return MakeHolder<TLzoDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzoCompress> >(s, bs); }); +    Add("y-lzf", [](auto s) { return MakeHolder<TLzfDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzfCompress> >(s, bs); }); +    Add("y-lzq", [](auto s) { return MakeHolder<TLzqDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzqCompress> >(s, bs); });  #endif -    Add("y-bzip2", [](auto s) { return MakeHolder<TBZipDecompress>(s); }, [](auto s) { return MakeHolder<TBZipCompress>(s); });  -    Add("y-lzma", [](auto s) { return MakeHolder<TLzmaDecompress>(s); }, [](auto s) { return MakeHolder<TLzmaCompress>(s); });  +    Add("y-bzip2", [](auto s) { return MakeHolder<TBZipDecompress>(s); }, [](auto s) { return MakeHolder<TBZipCompress>(s); }); +    Add("y-lzma", [](auto s) { return MakeHolder<TLzmaDecompress>(s); }, [](auto s) { return MakeHolder<TLzmaCompress>(s); }); -    for (auto codecName : NBlockCodecs::ListAllCodecs()) {  -        if (codecName.StartsWith("zstd06")) {  -            continue;  +    for (auto codecName : NBlockCodecs::ListAllCodecs()) { +        if (codecName.StartsWith("zstd06")) { +            continue;          } -        if (codecName.StartsWith("zstd08")) {  -            continue;  +        if (codecName.StartsWith("zstd08")) { +            continue;          } -        auto codec = NBlockCodecs::Codec(codecName);  +        auto codec = NBlockCodecs::Codec(codecName); -        auto enc = [codec](auto s) {  -            return MakeHolder<NBlockCodecs::TCodedOutput>(s, codec, 32 * 1024);  -        };  +        auto enc = [codec](auto s) { +            return MakeHolder<NBlockCodecs::TCodedOutput>(s, codec, 32 * 1024); +        }; -        auto dec = [codec](auto s) {  -            return MakeHolder<NBlockCodecs::TDecodedInput>(s, codec);  +        auto dec = [codec](auto s) { +            return MakeHolder<NBlockCodecs::TDecodedInput>(s, codec);          }; -        Add(TString("z-") + codecName, dec, enc);  +        Add(TString("z-") + codecName, dec, enc);      }  } -void TCompressionCodecFactory::Add(TStringBuf name, TDecoderConstructor d, TEncoderConstructor e) {  -    Strings_.emplace_back(name);  -    Codecs_[Strings_.back()] = TCodec{d, e};  -    BestCodecs_.emplace_back(Strings_.back());  +void TCompressionCodecFactory::Add(TStringBuf name, TDecoderConstructor d, TEncoderConstructor e) { +    Strings_.emplace_back(name); +    Codecs_[Strings_.back()] = TCodec{d, e}; +    BestCodecs_.emplace_back(Strings_.back());  } diff --git a/library/cpp/http/io/compression.h b/library/cpp/http/io/compression.h index d93f628739e..f16c4a18ebb 100644 --- a/library/cpp/http/io/compression.h +++ b/library/cpp/http/io/compression.h @@ -1,52 +1,52 @@  #pragma once -#include "stream.h"  +#include "stream.h"  #include <util/generic/deque.h> -#include <util/generic/hash.h>  +#include <util/generic/hash.h> -class TCompressionCodecFactory {  +class TCompressionCodecFactory {  public: -    using TDecoderConstructor = std::function<THolder<IInputStream>(IInputStream*)>;  -    using TEncoderConstructor = std::function<THolder<IOutputStream>(IOutputStream*)>;  +    using TDecoderConstructor = std::function<THolder<IInputStream>(IInputStream*)>; +    using TEncoderConstructor = std::function<THolder<IOutputStream>(IOutputStream*)>; -    TCompressionCodecFactory();  +    TCompressionCodecFactory(); -    static inline TCompressionCodecFactory& Instance() noexcept {  -        return *SingletonWithPriority<TCompressionCodecFactory, 0>();  -    }  +    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;  -        }  +    inline const TDecoderConstructor* FindDecoder(TStringBuf name) const { +        if (auto codec = Codecs_.FindPtr(name)) { +            return &codec->Decoder; +        } -        return nullptr;  -    }  +        return nullptr; +    } -    inline const TEncoderConstructor* FindEncoder(TStringBuf name) const {  -        if (auto codec = Codecs_.FindPtr(name)) {  -            return &codec->Encoder;  -        }  +    inline const TEncoderConstructor* FindEncoder(TStringBuf name) const { +        if (auto codec = Codecs_.FindPtr(name)) { +            return &codec->Encoder; +        } -        return nullptr;  -    }  +        return nullptr; +    } -    inline TArrayRef<const TStringBuf> GetBestCodecs() const {  -        return BestCodecs_;  -    }  +    inline TArrayRef<const TStringBuf> GetBestCodecs() const { +        return BestCodecs_; +    }  private: -    void Add(TStringBuf name, TDecoderConstructor d, TEncoderConstructor e);  +    void Add(TStringBuf name, TDecoderConstructor d, TEncoderConstructor e); -    struct TCodec {  -        TDecoderConstructor Decoder;  -        TEncoderConstructor Encoder;  -    };  +    struct TCodec { +        TDecoderConstructor Decoder; +        TEncoderConstructor Encoder; +    };      TDeque<TString> Strings_; -    THashMap<TStringBuf, TCodec> Codecs_;  -    TVector<TStringBuf> BestCodecs_;  +    THashMap<TStringBuf, TCodec> Codecs_; +    TVector<TStringBuf> BestCodecs_;  };  namespace NHttp { diff --git a/library/cpp/http/io/compression_ut.cpp b/library/cpp/http/io/compression_ut.cpp index bde9de4c885..2f3d131f8c3 100644 --- a/library/cpp/http/io/compression_ut.cpp +++ b/library/cpp/http/io/compression_ut.cpp @@ -1,5 +1,5 @@  #include "stream.h" -#include "compression.h"  +#include "compression.h"  #include <library/cpp/testing/unittest/registar.h>  #include <library/cpp/testing/unittest/tests_data.h> @@ -7,41 +7,41 @@  #include <util/stream/zlib.h>  #include <util/generic/hash_set.h> -Y_UNIT_TEST_SUITE(THttpCompressionTest) {  -    static const TString DATA = "I'm a teapot";  +Y_UNIT_TEST_SUITE(THttpCompressionTest) { +    static const TString DATA = "I'm a teapot"; -    Y_UNIT_TEST(TestGetBestCodecs) {  -        UNIT_ASSERT(TCompressionCodecFactory::Instance().GetBestCodecs().size() > 0);  +    Y_UNIT_TEST(TestGetBestCodecs) { +        UNIT_ASSERT(TCompressionCodecFactory::Instance().GetBestCodecs().size() > 0);      } -    Y_UNIT_TEST(TestEncoder) {  -        TStringStream buffer;  +    Y_UNIT_TEST(TestEncoder) { +        TStringStream buffer;          { -            auto encoder = TCompressionCodecFactory::Instance().FindEncoder("gzip");  -            UNIT_ASSERT(encoder);  +            auto encoder = TCompressionCodecFactory::Instance().FindEncoder("gzip"); +            UNIT_ASSERT(encoder); -            auto encodedStream = (*encoder)(&buffer);  -            encodedStream->Write(DATA);  +            auto encodedStream = (*encoder)(&buffer); +            encodedStream->Write(DATA);          } -        TZLibDecompress decompressor(&buffer);  -        UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA);  +        TZLibDecompress decompressor(&buffer); +        UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA);      } -    Y_UNIT_TEST(TestDecoder) {  -        TStringStream buffer;  +    Y_UNIT_TEST(TestDecoder) { +        TStringStream buffer;          { -            TZLibCompress compressor(TZLibCompress::TParams(&buffer).SetType(ZLib::GZip));  -            compressor.Write(DATA);  +            TZLibCompress compressor(TZLibCompress::TParams(&buffer).SetType(ZLib::GZip)); +            compressor.Write(DATA);          } -        auto decoder = TCompressionCodecFactory::Instance().FindDecoder("gzip");  -        UNIT_ASSERT(decoder);  +        auto decoder = TCompressionCodecFactory::Instance().FindDecoder("gzip"); +        UNIT_ASSERT(decoder); -        auto decodedStream = (*decoder)(&buffer);  -        UNIT_ASSERT_EQUAL(decodedStream->ReadAll(), DATA);  +        auto decodedStream = (*decoder)(&buffer); +        UNIT_ASSERT_EQUAL(decodedStream->ReadAll(), DATA);      }      Y_UNIT_TEST(TestChooseBestCompressionScheme) { @@ -57,4 +57,4 @@ Y_UNIT_TEST_SUITE(THttpCompressionTest) {          accepted.insert("*");          UNIT_ASSERT_VALUES_EQUAL("gzip", NHttp::ChooseBestCompressionScheme(checkAccepted, {"gzip", "deflate"}));      } -} // THttpCompressionTest suite  +} // THttpCompressionTest suite diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp index cc6c7e887b0..6689be684fc 100644 --- a/library/cpp/http/io/stream.cpp +++ b/library/cpp/http/io/stream.cpp @@ -1,11 +1,11 @@  #include "stream.h" -  -#include "compression.h"  + +#include "compression.h"  #include "chunk.h" -#include <util/stream/buffered.h>  +#include <util/stream/buffered.h>  #include <util/stream/length.h> -#include <util/stream/multi.h>  +#include <util/stream/multi.h>  #include <util/stream/null.h>  #include <util/stream/tee.h> @@ -352,9 +352,9 @@ private:              }          } -        if (auto decoder = TCompressionCodecFactory::Instance().FindDecoder(p.LZipped)) {  +        if (auto decoder = TCompressionCodecFactory::Instance().FindDecoder(p.LZipped)) {              ContentEncoded_ = true; -            Input_ = Streams_.Add((*decoder)(Input_).Release());  +            Input_ = Streams_.Add((*decoder)(Input_).Release());          }          KeepAlive_ = p.KeepAlive; @@ -427,7 +427,7 @@ bool THttpInput::AcceptEncoding(const TString& coding) const {      return Impl_->AcceptEncoding(coding);  } -TString THttpInput::BestCompressionScheme(TArrayRef<const TStringBuf> codings) const {  +TString THttpInput::BestCompressionScheme(TArrayRef<const TStringBuf> codings) const {      return NHttp::ChooseBestCompressionScheme(          [this](const TString& coding) {              return AcceptEncoding(coding); @@ -437,7 +437,7 @@ TString THttpInput::BestCompressionScheme(TArrayRef<const TStringBuf> codings) c  }  TString THttpInput::BestCompressionScheme() const { -    return BestCompressionScheme(TCompressionCodecFactory::Instance().GetBestCodecs());  +    return BestCompressionScheme(TCompressionCodecFactory::Instance().GetBestCodecs());  }  bool THttpInput::GetContentLength(ui64& value) const noexcept { @@ -504,7 +504,7 @@ public:          , Version_(1100)          , KeepAliveEnabled_(false)          , BodyEncodingEnabled_(true) -        , CompressionHeaderEnabled_(true)  +        , CompressionHeaderEnabled_(true)          , Finished_(false)      {      } @@ -583,7 +583,7 @@ public:          return Headers_;      } -    inline void EnableCompression(TArrayRef<const TStringBuf> schemas) {  +    inline void EnableCompression(TArrayRef<const TStringBuf> schemas) {          ComprSchemas_ = schemas;      } @@ -595,12 +595,12 @@ public:          BodyEncodingEnabled_ = enable;      } -    inline void EnableCompressionHeader(bool enable) {  -        CompressionHeaderEnabled_ = enable;  -    }  -  +    inline void EnableCompressionHeader(bool enable) { +        CompressionHeaderEnabled_ = enable; +    } +      inline bool IsCompressionEnabled() const noexcept { -        return !ComprSchemas_.empty();  +        return !ComprSchemas_.empty();      }      inline bool IsKeepAliveEnabled() const noexcept { @@ -611,10 +611,10 @@ public:          return BodyEncodingEnabled_;      } -    inline bool IsCompressionHeaderEnabled() const noexcept {  -        return CompressionHeaderEnabled_;  -    }  -  +    inline bool IsCompressionHeaderEnabled() const noexcept { +        return CompressionHeaderEnabled_; +    } +      inline bool CanBeKeepAlive() const noexcept {          return SupportChunkedTransfer() && IsKeepAliveEnabled() && (Request_ ? Request_->IsKeepAlive() : true);      } @@ -773,7 +773,7 @@ private:          if (IsHttpResponse()) {              if (Request_ && IsCompressionEnabled() && HasResponseBody()) { -                TString scheme = Request_->BestCompressionScheme(ComprSchemas_);  +                TString scheme = Request_->BestCompressionScheme(ComprSchemas_);                  if (scheme != "identity") {                      AddOrReplaceHeader(THttpInputHeader("Content-Encoding", scheme));                      RemoveHeader("Content-Length"); @@ -794,12 +794,12 @@ private:      inline TString BuildAcceptEncoding() const {          TString ret; -        for (const auto& coding : ComprSchemas_) {  +        for (const auto& coding : ComprSchemas_) {              if (ret) {                  ret += ", ";              } -            ret += coding;  +            ret += coding;          }          return ret; @@ -807,7 +807,7 @@ private:      inline void RebuildStream() {          bool keepAlive = false; -        const TCompressionCodecFactory::TEncoderConstructor* encoder = nullptr;  +        const TCompressionCodecFactory::TEncoderConstructor* encoder = nullptr;          bool chunked = false;          bool haveContentLength = false; @@ -818,7 +818,7 @@ private:              if (hl == TStringBuf("connection")) {                  keepAlive = to_lower(header.Value()) == TStringBuf("keep-alive");              } else if (IsCompressionHeaderEnabled() && hl == TStringBuf("content-encoding")) { -                encoder = TCompressionCodecFactory::Instance().FindEncoder(to_lower(header.Value()));  +                encoder = TCompressionCodecFactory::Instance().FindEncoder(to_lower(header.Value()));              } else if (hl == TStringBuf("transfer-encoding")) {                  chunked = to_lower(header.Value()) == TStringBuf("chunked");              } else if (hl == TStringBuf("content-length")) { @@ -838,7 +838,7 @@ private:          Output_ = Streams_.Add(new TTeeOutput(Output_, &SizeCalculator_));          if (IsBodyEncodingEnabled() && encoder) { -            Output_ = Streams_.Add((*encoder)(Output_).Release());  +            Output_ = Streams_.Add((*encoder)(Output_).Release());          }      } @@ -865,11 +865,11 @@ private:      THttpInput* Request_;      size_t Version_; -    TArrayRef<const TStringBuf> ComprSchemas_;  +    TArrayRef<const TStringBuf> ComprSchemas_;      bool KeepAliveEnabled_;      bool BodyEncodingEnabled_; -    bool CompressionHeaderEnabled_;  +    bool CompressionHeaderEnabled_;      bool Finished_; @@ -911,15 +911,15 @@ const THttpHeaders& THttpOutput::SentHeaders() const noexcept {  void THttpOutput::EnableCompression(bool enable) {      if (enable) { -        EnableCompression(TCompressionCodecFactory::Instance().GetBestCodecs());  +        EnableCompression(TCompressionCodecFactory::Instance().GetBestCodecs());      } else { -        TArrayRef<TStringBuf> codings;  -        EnableCompression(codings);  +        TArrayRef<TStringBuf> codings; +        EnableCompression(codings);      }  } -void THttpOutput::EnableCompression(TArrayRef<const TStringBuf> schemas) {  -    Impl_->EnableCompression(schemas);  +void THttpOutput::EnableCompression(TArrayRef<const TStringBuf> schemas) { +    Impl_->EnableCompression(schemas);  }  void THttpOutput::EnableKeepAlive(bool enable) { @@ -930,10 +930,10 @@ void THttpOutput::EnableBodyEncoding(bool enable) {      Impl_->EnableBodyEncoding(enable);  } -void THttpOutput::EnableCompressionHeader(bool enable) {  -    Impl_->EnableCompressionHeader(enable);  -}  -  +void THttpOutput::EnableCompressionHeader(bool enable) { +    Impl_->EnableCompressionHeader(enable); +} +  bool THttpOutput::IsKeepAliveEnabled() const noexcept {      return Impl_->IsKeepAliveEnabled();  } @@ -946,10 +946,10 @@ bool THttpOutput::IsCompressionEnabled() const noexcept {      return Impl_->IsCompressionEnabled();  } -bool THttpOutput::IsCompressionHeaderEnabled() const noexcept {  -    return Impl_->IsCompressionHeaderEnabled();  -}  -  +bool THttpOutput::IsCompressionHeaderEnabled() const noexcept { +    return Impl_->IsCompressionHeaderEnabled(); +} +  bool THttpOutput::CanBeKeepAlive() const noexcept {      return Impl_->CanBeKeepAlive();  } @@ -1000,6 +1000,6 @@ void SendMinimalHttpRequest(TSocket& s, const TStringBuf& host, const TStringBuf      output.Finish();  } -TArrayRef<const TStringBuf> SupportedCodings() {  -    return TCompressionCodecFactory::Instance().GetBestCodecs();  +TArrayRef<const TStringBuf> SupportedCodings() { +    return TCompressionCodecFactory::Instance().GetBestCodecs();  } diff --git a/library/cpp/http/io/stream.h b/library/cpp/http/io/stream.h index 43f77903997..78ca4fc814c 100644 --- a/library/cpp/http/io/stream.h +++ b/library/cpp/http/io/stream.h @@ -71,7 +71,7 @@ public:      /// любые типы кодирования, выбирается gzip. В противном случае      /// из списка типов кодирования выбирается лучший из поддерживаемых сервером.      TString BestCompressionScheme() const; -    TString BestCompressionScheme(TArrayRef<const TStringBuf> codings) const;  +    TString BestCompressionScheme(TArrayRef<const TStringBuf> codings) const;      /// Если заголовки содержат Content-Length, возвращает true и      /// записывает значение из заголовка в value @@ -110,7 +110,7 @@ public:      /// Устанавливает режим, при котором сервер выдает ответ в упакованном виде.      void EnableCompression(bool enable); -    void EnableCompression(TArrayRef<const TStringBuf> schemas);  +    void EnableCompression(TArrayRef<const TStringBuf> schemas);      /// Устанавливает режим, при котором соединение с сервером не завершается      /// после окончания транзакции. @@ -120,10 +120,10 @@ public:      /// с заголовками Content-Encoding и Transfer-Encoding (включен по умолчанию)      void EnableBodyEncoding(bool enable); -    /// Устанавливает режим, при котором тело HTTP-ответа сжимается кодеком  -    /// указанным в Content-Encoding (включен по умолчанию)  -    void EnableCompressionHeader(bool enable);  -  +    /// Устанавливает режим, при котором тело HTTP-ответа сжимается кодеком +    /// указанным в Content-Encoding (включен по умолчанию) +    void EnableCompressionHeader(bool enable); +      /// Проверяет, производится ли выдача ответов в упакованном виде.      bool IsCompressionEnabled() const noexcept; @@ -134,10 +134,10 @@ public:      /// с заголовками Content-Encoding и Transfer-Encoding      bool IsBodyEncodingEnabled() const noexcept; -    /// Проверяет, сжимается ли тело HTTP-ответа кодеком  -    /// указанным в Content-Encoding  -    bool IsCompressionHeaderEnabled() const noexcept;  -  +    /// Проверяет, сжимается ли тело HTTP-ответа кодеком +    /// указанным в Content-Encoding +    bool IsCompressionHeaderEnabled() const noexcept; +      /*       * is this connection can be really keep-alive       */ @@ -173,6 +173,6 @@ unsigned ParseHttpRetCode(const TStringBuf& ret);  /// Отправляет HTTP-серверу запрос с минимумом необходимых заголовков.  void SendMinimalHttpRequest(TSocket& s, const TStringBuf& host, const TStringBuf& request, const TStringBuf& agent = "YandexSomething/1.0", const TStringBuf& from = "[email protected]"); -TArrayRef<const TStringBuf> SupportedCodings();  +TArrayRef<const TStringBuf> SupportedCodings();  /// @} diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 47060a39481..1ea35df675a 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -14,7 +14,7 @@  #include <util/stream/zlib.h>  #include <util/stream/null.h> -Y_UNIT_TEST_SUITE(THttpStreamTest) {  +Y_UNIT_TEST_SUITE(THttpStreamTest) {      class TTestHttpServer: public THttpServer::ICallBack {          class TRequest: public THttpClientRequestEx {          public: @@ -443,7 +443,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {      Y_UNIT_TEST(CodecsPriority) {          TMemoryInput request("GET / HTTP/1.1\r\nAccept-Encoding: gzip, br\r\n\r\n"); -        TVector<TStringBuf> codecs = {"br", "gzip"};  +        TVector<TStringBuf> codecs = {"br", "gzip"};          THttpInput i(&request);          TString result; @@ -451,7 +451,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {          THttpOutput httpOut(&out, &i);          httpOut.EnableKeepAlive(true); -        httpOut.EnableCompression(codecs);  +        httpOut.EnableCompression(codecs);          httpOut << "HTTP/1.1 200 OK\r\n";          char answer[] = "Mary had a little lamb.";          httpOut << "Content-Length: " << strlen(answer) << "\r\n" @@ -466,7 +466,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {      Y_UNIT_TEST(CodecsPriority2) {          TMemoryInput request("GET / HTTP/1.1\r\nAccept-Encoding: gzip, br\r\n\r\n"); -        TVector<TStringBuf> codecs = {"gzip", "br"};  +        TVector<TStringBuf> codecs = {"gzip", "br"};          THttpInput i(&request);          TString result; @@ -474,7 +474,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {          THttpOutput httpOut(&out, &i);          httpOut.EnableKeepAlive(true); -        httpOut.EnableCompression(codecs);  +        httpOut.EnableCompression(codecs);          httpOut << "HTTP/1.1 200 OK\r\n";          char answer[] = "Mary had a little lamb.";          httpOut << "Content-Length: " << strlen(answer) << "\r\n" @@ -665,27 +665,27 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {          UNIT_ASSERT(!result.Contains(TStringBuf("0\r\n")));      } -    Y_UNIT_TEST(TestHttpOutputDisableCompressionHeader) {  -        TMemoryInput request("GET / HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n");  -        const TString data = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";  -  -        THttpInput httpInput(&request);  -        TString result;  -  -        {  -            TStringOutput output(result);  -            THttpOutput httpOutput(&output, &httpInput);  -            httpOutput.EnableCompressionHeader(false);  -            httpOutput << "HTTP/1.1 200 OK\r\n"  -                   "content-encoding: gzip\r\n"  -                   "\r\n" + data;  -            httpOutput.Finish();  -        }  -  -        UNIT_ASSERT(result.Contains("content-encoding: gzip"));  -        UNIT_ASSERT(result.Contains(data));  -    }  -  +    Y_UNIT_TEST(TestHttpOutputDisableCompressionHeader) { +        TMemoryInput request("GET / HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n"); +        const TString data = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"; + +        THttpInput httpInput(&request); +        TString result; + +        { +            TStringOutput output(result); +            THttpOutput httpOutput(&output, &httpInput); +            httpOutput.EnableCompressionHeader(false); +            httpOutput << "HTTP/1.1 200 OK\r\n" +                   "content-encoding: gzip\r\n" +                   "\r\n" + data; +            httpOutput.Finish(); +        } + +        UNIT_ASSERT(result.Contains("content-encoding: gzip")); +        UNIT_ASSERT(result.Contains(data)); +    } +      size_t DoTestHttpOutputSize(const TString& res, bool enableCompession) {          TTestHttpServer serverImpl(res);          TPortManager pm; @@ -729,4 +729,4 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {          UNIT_ASSERT_VALUES_EQUAL(res.size(), DoTestHttpOutputSize(res, false));          UNIT_ASSERT_VALUES_UNEQUAL(res.size(), DoTestHttpOutputSize(res, true));      } -} // THttpStreamTest suite  +} // THttpStreamTest suite diff --git a/library/cpp/http/io/ut/ya.make b/library/cpp/http/io/ut/ya.make index fbdb56a03ac..84f6949db33 100644 --- a/library/cpp/http/io/ut/ya.make +++ b/library/cpp/http/io/ut/ya.make @@ -8,8 +8,8 @@ PEERDIR(  SRCS(      chunk_ut.cpp -    compression_ut.cpp  -    headers_ut.cpp  +    compression_ut.cpp +    headers_ut.cpp      stream_ut.cpp  ) diff --git a/library/cpp/http/io/ya.make b/library/cpp/http/io/ya.make index ed4f88a4b6e..dcfbd798856 100644 --- a/library/cpp/http/io/ya.make +++ b/library/cpp/http/io/ya.make @@ -14,9 +14,9 @@ PEERDIR(  SRCS(      chunk.cpp -    compression.cpp  +    compression.cpp      headers.cpp -    stream.cpp  +    stream.cpp  )  END()  | 
