aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/http/http_client.h
blob: 97321c4c9d3ddbd247d0eb12b25e39c07d5e7bfc (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
#pragma once

#include "fwd.h"

#include <yt/cpp/mapreduce/interface/fwd.h>

#include <util/datetime/base.h>

#include <util/generic/maybe.h>
#include <util/generic/string.h>

#include <util/stream/fwd.h>

#include <memory>

namespace NYT::NHttpClient {

////////////////////////////////////////////////////////////////////////////////

struct THttpConfig
{
    TDuration SocketTimeout = TDuration::Zero();
};

////////////////////////////////////////////////////////////////////////////////

class IHttpResponse
{
public:
    virtual ~IHttpResponse() = default;

    virtual int GetStatusCode() = 0;
    virtual IInputStream* GetResponseStream() = 0;
    virtual TString GetResponse() = 0;
    virtual TString GetRequestId() const = 0;
};

class IHttpRequest
{
public:
    virtual ~IHttpRequest() = default;

    virtual IOutputStream* GetStream() = 0;
    virtual IHttpResponsePtr Finish() = 0;
};


class IHttpClient
{
public:
    virtual ~IHttpClient() = default;

    virtual IHttpResponsePtr Request(const TString& url, const TString& requestId, const THttpConfig& config, const THttpHeader& header, TMaybe<TStringBuf> body = {}) = 0;

    virtual IHttpResponsePtr Request(const TString& url, const TString& requestId, const THttpHeader& header, TMaybe<TStringBuf> body = {})
    {
        return Request(url, requestId, /*config*/ {}, header, body);
    }

    virtual IHttpRequestPtr StartRequest(const TString& url, const TString& requestId, const THttpConfig& config, const THttpHeader& header) = 0;

    virtual IHttpRequestPtr StartRequest(const TString& url, const TString& requestId, const THttpHeader& header)
    {
        return StartRequest(url, requestId, /*config*/ {}, header);
    }
};

////////////////////////////////////////////////////////////////////////////////

IHttpClientPtr CreateDefaultHttpClient();

IHttpClientPtr CreateCoreHttpClient(bool useTLS, const TConfigPtr& config);

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NHttpClient