aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/rain_check/http/client.h
blob: b7f822ae10c49fed25350451a50bf886596442b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once

#include <library/cpp/messagebus/rain_check/core/task.h>

#include <library/cpp/http/misc/httpcodes.h>

#include <util/generic/maybe.h>
#include <util/generic/ptr.h>
#include <util/generic/string.h>
#include <util/system/defaults.h>
#include <util/system/yassert.h>

class THttpHeaders;

namespace NNeh {
    class IProtocol; 
    struct TResponse; 
} 

namespace NRainCheck {
    class THttpCallback; 
    class THttpClientService; 

    class THttpFuture: public TSubtaskCompletion { 
    public: 
        enum EError { 
            NoError = 0, 

            CantResolveNameError = 1, 
            BadHttpCodeError = 2, 

            OtherError = 100 
        }; 

    private: 
        friend class THttpCallback; 
        friend class THttpClientService; 

    public: 
        THttpFuture(); 
        ~THttpFuture() override; 

        bool HasHttpCode() const; 
        bool HasResponseBody() const; 

        ui32 GetHttpCode() const; 
        TString GetResponseBody() const; 

        bool HasError() const; 
        EError GetErrorCode() const; 
        TString GetErrorDescription() const; 

    private: 
        void SetDoneAndSchedule(TAutoPtr<NNeh::TResponse> response); 
        void SetFail(EError errorCode, const TStringBuf& errorDescription); 

    private: 
        TTaskRunnerBase* Task; 
        TMaybe<HttpCodes> HttpCode; 
        THolder<NNeh::TResponse> Response; 
        EError ErrorCode; 
        TString ErrorDescription; 
    }; 

    class THttpClientService { 
    public: 
        THttpClientService(); 
        virtual ~THttpClientService(); 

        void Send(const TString& request, THttpFuture* future); 
        void SendPost(TString addr, const TString& data, const THttpHeaders& headers, THttpFuture* future); 

    private: 
        NNeh::IProtocol* const GetProtocol; 
        NNeh::IProtocol* const FullProtocol; 
    }; 

}