diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/http/fetch/httpload.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/http/fetch/httpload.h')
-rw-r--r-- | library/cpp/http/fetch/httpload.h | 264 |
1 files changed, 132 insertions, 132 deletions
diff --git a/library/cpp/http/fetch/httpload.h b/library/cpp/http/fetch/httpload.h index 5fc03d4be8..e22e4b809e 100644 --- a/library/cpp/http/fetch/httpload.h +++ b/library/cpp/http/fetch/httpload.h @@ -1,9 +1,9 @@ #pragma once -#include "httpagent.h" -#include "httpparser.h" -#include "http_digest.h" - +#include "httpagent.h" +#include "httpparser.h" +#include "http_digest.h" + #include <util/system/compat.h> #include <util/string/vector.h> #include <util/network/ip.h> @@ -20,7 +20,7 @@ /********************************************************/ // This class is used as a base one for flexible // socket handling -class socketAbstractHandler { +class socketAbstractHandler { public: virtual bool Good() = 0; @@ -36,12 +36,12 @@ public: virtual ssize_t read(void* buffer, ssize_t buflen) = 0; - virtual ~socketAbstractHandler() { - } + virtual ~socketAbstractHandler() { + } protected: - socketAbstractHandler() { - } + socketAbstractHandler() { + } }; /********************************************************/ @@ -49,54 +49,54 @@ protected: // socketAbstractHandler // (it is used by template scheme, // so it does not have virtual methods) -class TSocketHandlerPtr { +class TSocketHandlerPtr { protected: - socketAbstractHandler* Handler_; + socketAbstractHandler* Handler_; public: - TSocketHandlerPtr() - : Handler_(nullptr) - { - } + TSocketHandlerPtr() + : Handler_(nullptr) + { + } - virtual ~TSocketHandlerPtr() { - delete Handler_; - } + virtual ~TSocketHandlerPtr() { + delete Handler_; + } - int Good() { - return (Handler_ && Handler_->Good()); - } + int Good() { + return (Handler_ && Handler_->Good()); + } - int Connect(const TAddrList& addrs, TDuration Timeout) { - return (Handler_) ? Handler_->Connect(addrs, Timeout) : 1; + int Connect(const TAddrList& addrs, TDuration Timeout) { + return (Handler_) ? Handler_->Connect(addrs, Timeout) : 1; } - void Disconnect() { - if (Handler_) - Handler_->Disconnect(); + void Disconnect() { + if (Handler_) + Handler_->Disconnect(); } - void shutdown() { - if (Handler_) - Handler_->shutdown(); + void shutdown() { + if (Handler_) + Handler_->shutdown(); } - bool send(const char* message, ssize_t messlen) { - return (Handler_) ? Handler_->send(message, messlen) : false; + bool send(const char* message, ssize_t messlen) { + return (Handler_) ? Handler_->send(message, messlen) : false; } - virtual bool peek() { - return (Handler_) ? Handler_->peek() : false; + virtual bool peek() { + return (Handler_) ? Handler_->peek() : false; } - virtual ssize_t read(void* buffer, ssize_t buflen) { - return (Handler_) ? Handler_->read(buffer, buflen) : 0; + virtual ssize_t read(void* buffer, ssize_t buflen) { + return (Handler_) ? Handler_->read(buffer, buflen) : 0; } - void setHandler(socketAbstractHandler* handler) { - if (Handler_) - delete Handler_; - Handler_ = handler; + void setHandler(socketAbstractHandler* handler) { + if (Handler_) + delete Handler_; + Handler_ = handler; } }; @@ -108,58 +108,58 @@ using httpSpecialAgent = THttpAgent<TSocketHandlerPtr>; /********************************************************/ // Regular handler is used as implementation of // socketAbstractHandler for work through HTTP protocol -class socketRegularHandler: public socketAbstractHandler { -protected: - TSimpleSocketHandler Socket_; +class socketRegularHandler: public socketAbstractHandler { +protected: + TSimpleSocketHandler Socket_; -public: - socketRegularHandler() - : Socket_() - { - } +public: + socketRegularHandler() + : Socket_() + { + } - bool Good() override { - return Socket_.Good(); + bool Good() override { + return Socket_.Good(); } - int Connect(const TAddrList& addrs, TDuration Timeout) override { + int Connect(const TAddrList& addrs, TDuration Timeout) override { return Socket_.Connect(addrs, Timeout); } - void Disconnect() override { - Socket_.Disconnect(); + void Disconnect() override { + Socket_.Disconnect(); } - void shutdown() override { + void shutdown() override { //Do not block writing to socket //There are servers that works in a bad way with this //mSocket.shutdown(); } - bool send(const char* message, ssize_t messlen) override { - return Socket_.send(message, messlen); + bool send(const char* message, ssize_t messlen) override { + return Socket_.send(message, messlen); } - bool peek() override { - return Socket_.peek(); + bool peek() override { + return Socket_.peek(); } - ssize_t read(void* buffer, ssize_t buflen) override { - return Socket_.read(buffer, buflen); + ssize_t read(void* buffer, ssize_t buflen) override { + return Socket_.read(buffer, buflen); } }; /********************************************************/ // The base factory that allows to choose an appropriate // socketAbstractHandler implementation by url schema - -class socketHandlerFactory { -public: - virtual ~socketHandlerFactory() { - } + +class socketHandlerFactory { +public: + virtual ~socketHandlerFactory() { + } //returns mHandler_HTTP for correct HTTP-based url - virtual socketAbstractHandler* chooseHandler(const THttpURL& url); + virtual socketAbstractHandler* chooseHandler(const THttpURL& url); static socketHandlerFactory sInstance; }; @@ -168,138 +168,138 @@ public: // Section 2: the configurates tool to parse an HTTP-response /********************************************************/ -class httpAgentReader: public THttpParserGeneric<1> { -protected: - THttpAuthHeader Header_; - httpSpecialAgent& Agent_; +class httpAgentReader: public THttpParserGeneric<1> { +protected: + THttpAuthHeader Header_; + httpSpecialAgent& Agent_; - char* Buffer_; - void* BufPtr_; - int BufSize_; - long BufRest_; + char* Buffer_; + void* BufPtr_; + int BufSize_; + long BufRest_; void readBuf(); - bool step() { - if (BufRest_ == 0) + bool step() { + if (BufRest_ == 0) readBuf(); if (eof()) return false; return true; } -public: - httpAgentReader(httpSpecialAgent& agent, - const char* baseUrl, - bool assumeConnectionClosed, - bool use_auth = false, - int bufSize = 0x1000); +public: + httpAgentReader(httpSpecialAgent& agent, + const char* baseUrl, + bool assumeConnectionClosed, + bool use_auth = false, + int bufSize = 0x1000); ~httpAgentReader(); - bool eof() { - return BufRest_ < 0; + bool eof() { + return BufRest_ < 0; } - int error() { - return Header_.error; + int error() { + return Header_.error; } - void setError(int errCode) { - Header_.error = errCode; + void setError(int errCode) { + Header_.error = errCode; } - const THttpAuthHeader* getAuthHeader() { - return &Header_; + const THttpAuthHeader* getAuthHeader() { + return &Header_; } - const THttpHeader* readHeader(); - long readPortion(void*& buf); - bool skipTheRest(); + const THttpHeader* readHeader(); + long readPortion(void*& buf); + bool skipTheRest(); }; /********************************************************/ // Section 3: the main class /********************************************************/ -class httpLoadAgent: public httpSpecialAgent { -protected: - socketHandlerFactory& Factory_; - bool HandleAuthorization_; - THttpURL URL_; - bool PersistentConn_; - httpAgentReader* Reader_; - TVector<TString> Headers_; - int ErrCode_; - char* RealHost_; - httpDigestHandler Digest_; +class httpLoadAgent: public httpSpecialAgent { +protected: + socketHandlerFactory& Factory_; + bool HandleAuthorization_; + THttpURL URL_; + bool PersistentConn_; + httpAgentReader* Reader_; + TVector<TString> Headers_; + int ErrCode_; + char* RealHost_; + httpDigestHandler Digest_; void clearReader(); bool doSetHost(const TAddrList& addrs); bool doStartRequest(); -public: - httpLoadAgent(bool handleAuthorization = false, - socketHandlerFactory& factory = socketHandlerFactory::sInstance); +public: + httpLoadAgent(bool handleAuthorization = false, + socketHandlerFactory& factory = socketHandlerFactory::sInstance); ~httpLoadAgent(); void setRealHost(const char* host); - void setIMS(const char* ifModifiedSince); + void setIMS(const char* ifModifiedSince); void addHeaderInstruction(const char* instr); void dropHeaderInstructions(); bool startRequest(const char* url, const char* url_to_merge = nullptr, - bool persistent = false, + bool persistent = false, const TAddrList& addrs = TAddrList()); // deprecated v4-only bool startRequest(const char* url, const char* url_to_merge, - bool persistent, - ui32 ip); + bool persistent, + ui32 ip); bool startRequest(const THttpURL& url, - bool persistent = false, + bool persistent = false, const TAddrList& addrs = TAddrList()); - bool setHost(const char* host_url, - const TAddrList& addrs = TAddrList()); + bool setHost(const char* host_url, + const TAddrList& addrs = TAddrList()); bool startOneRequest(const char* local_url); - const THttpAuthHeader* getAuthHeader() { - if (Reader_ && Reader_->getAuthHeader()->use_auth) - return Reader_->getAuthHeader(); + const THttpAuthHeader* getAuthHeader() { + if (Reader_ && Reader_->getAuthHeader()->use_auth) + return Reader_->getAuthHeader(); return nullptr; } - const THttpHeader* getHeader() { - if (Reader_) - return Reader_->getAuthHeader(); + const THttpHeader* getHeader() { + if (Reader_) + return Reader_->getAuthHeader(); return nullptr; } - const THttpURL& getURL() { - return URL_; + const THttpURL& getURL() { + return URL_; } - bool eof() { - if (Reader_) - return Reader_->eof(); + bool eof() { + if (Reader_) + return Reader_->eof(); return true; } - int error() { - if (ErrCode_) - return ErrCode_; - if (Reader_) - return Reader_->error(); + int error() { + if (ErrCode_) + return ErrCode_; + if (Reader_) + return Reader_->error(); return HTTP_BAD_URL; } - long readPortion(void*& buf) { - if (Reader_) - return Reader_->readPortion(buf); + long readPortion(void*& buf) { + if (Reader_) + return Reader_->readPortion(buf); return -1; } }; |