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
|
#pragma once
#include "query.h"
#include "request.h"
namespace NHttp {
struct TClientOptions {
#define DECLARE_FIELD(name, type, default) \
type name{default}; \
inline TClientOptions& Set##name(const type& value) { \
name = value; \
return *this; \
}
/// The size of stack of fetching coroutine.
DECLARE_FIELD(ExecutorStackSize, size_t, 1 << 20);
/// The number of fetching coroutines.
DECLARE_FIELD(FetchCoroutines, size_t, 3);
DECLARE_FIELD(Name, TString, "GlobalFetcher");
/// The lifetime of entries in the DNS cache (if zero then cache is not used).
DECLARE_FIELD(DnsCacheLifetime, TDuration, TDuration::Zero());
/// Established connections will be keept for further usage.
DECLARE_FIELD(KeepAlive, bool, false);
/// How long established connections should be keept.
DECLARE_FIELD(KeepAliveTimeout, TDuration, TDuration::Minutes(5));
#undef DECLARE_FIELD
};
/**
* Statefull fetching client.
* Can handle multiply fetching request simultaneously. Also it's may apply
* politeness policy to control load of each host.
*/
class TFetchClient {
public:
explicit TFetchClient(const TClientOptions& options = TClientOptions());
~TFetchClient();
/// Execute give fetch request in asynchronous fashion.
TFetchState Fetch(const TFetchQuery& query, NHttpFetcher::TCallBack cb);
private:
class TImpl;
THolder<TImpl> Impl_;
};
/// Execute give fetch request in synchronous fashion.
NHttpFetcher::TResultRef Fetch(const TFetchQuery& query);
/// Execute give fetch request in asynchronous fashion.
TFetchState FetchAsync(const TFetchQuery& query, NHttpFetcher::TCallBack cb);
}
|