diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/http/io/headers.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http/io/headers.cpp')
-rw-r--r-- | library/cpp/http/io/headers.cpp | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/library/cpp/http/io/headers.cpp b/library/cpp/http/io/headers.cpp index 4ec27a29e8..5d0d4f895d 100644 --- a/library/cpp/http/io/headers.cpp +++ b/library/cpp/http/io/headers.cpp @@ -1,64 +1,64 @@ -#include "headers.h" -#include "stream.h" - +#include "headers.h" +#include "stream.h" + #include <util/generic/strbuf.h> -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> #include <util/stream/output.h> #include <util/string/ascii.h> -#include <util/string/cast.h> -#include <util/string/strip.h> - +#include <util/string/cast.h> +#include <util/string/strip.h> + static inline TStringBuf Trim(const char* b, const char* e) noexcept { - return StripString(TStringBuf(b, e)); -} - + return StripString(TStringBuf(b, e)); +} + THttpInputHeader::THttpInputHeader(const TStringBuf header) { - size_t pos = header.find(':'); - + size_t pos = header.find(':'); + if (pos == TString::npos) { ythrow THttpParseException() << "can not parse http header(" << TString{header}.Quote() << ")"; - } - + } + Name_ = TString(header.cbegin(), header.cbegin() + pos); Value_ = ::ToString(Trim(header.cbegin() + pos + 1, header.cend())); -} - +} + THttpInputHeader::THttpInputHeader(TString name, TString value) : Name_(std::move(name)) , Value_(std::move(value)) -{ -} - +{ +} + void THttpInputHeader::OutTo(IOutputStream* stream) const { typedef IOutputStream::TPart TPart; - - const TPart parts[] = { - TPart(Name_), - TPart(": ", 2), - TPart(Value_), - TPart::CrLf(), - }; - - stream->Write(parts, sizeof(parts) / sizeof(*parts)); -} - + + const TPart parts[] = { + TPart(Name_), + TPart(": ", 2), + TPart(Value_), + TPart::CrLf(), + }; + + stream->Write(parts, sizeof(parts) / sizeof(*parts)); +} + THttpHeaders::THttpHeaders(IInputStream* stream) { TString header; TString line; - + bool rdOk = stream->ReadLine(header); while (rdOk && !header.empty()) { rdOk = stream->ReadLine(line); - + if (rdOk && ((line[0] == ' ') || (line[0] == '\t'))) { header += line; } else { AddHeader(THttpInputHeader(header)); header = line; - } - } -} - + } + } +} + bool THttpHeaders::HasHeader(const TStringBuf header) const { return FindHeader(header); } @@ -85,24 +85,24 @@ void THttpHeaders::AddOrReplaceHeader(const THttpInputHeader& header) { for (auto& hdr : Headers_) { if (AsciiCompareIgnoreCase(hdr.Name(), header.Name()) == 0) { hdr = header; - return; - } - } - - AddHeader(header); -} - + return; + } + } + + AddHeader(header); +} + void THttpHeaders::AddHeader(THttpInputHeader header) { Headers_.push_back(std::move(header)); -} - +} + void THttpHeaders::OutTo(IOutputStream* stream) const { - for (TConstIterator header = Begin(); header != End(); ++header) { - header->OutTo(stream); - } -} - -template <> + for (TConstIterator header = Begin(); header != End(); ++header) { + header->OutTo(stream); + } +} + +template <> void Out<THttpHeaders>(IOutputStream& out, const THttpHeaders& h) { - h.OutTo(&out); -} + h.OutTo(&out); +} |