|
10 | 10 |
|
11 | 11 | namespace launchdarkly::config::detail::builders {
|
12 | 12 |
|
| 13 | +/** |
| 14 | + * Class used for building a set of HttpProperties. |
| 15 | + * @tparam SDK The SDK type to build properties for. This affects the default |
| 16 | + * values of the built properties. |
| 17 | + */ |
13 | 18 | template <typename SDK>
|
14 | 19 | class HttpPropertiesBuilder {
|
15 | 20 | public:
|
16 |
| - HttpPropertiesBuilder() = default; |
| 21 | + /** |
| 22 | + * Construct a new HttpPropertiesBuilder. The builder will use the default |
| 23 | + * properties based on the SDK type. Setting a property will override |
| 24 | + * the default value. |
| 25 | + */ |
| 26 | + HttpPropertiesBuilder(); |
17 | 27 |
|
| 28 | + /** |
| 29 | + * Create a properties builder from an initial set of properties. |
| 30 | + * This can be useful when extending a set of properties for a request. |
| 31 | + * For instance to add extra headers. |
| 32 | + * |
| 33 | + * ``` |
| 34 | + * HttpPropertiesBuilder(my_properties) |
| 35 | + * .Header("authorization", "my-key") |
| 36 | + * .Build(); |
| 37 | + * ``` |
| 38 | + * |
| 39 | + * @param properties The properties to start with. |
| 40 | + */ |
| 41 | + HttpPropertiesBuilder(built::HttpProperties properties); |
| 42 | + |
| 43 | + /** |
| 44 | + * The network connection timeout. |
| 45 | + * |
| 46 | + * @param connect_timeout The connect timeout. |
| 47 | + * @return A reference to this builder. |
| 48 | + */ |
18 | 49 | HttpPropertiesBuilder& ConnectTimeout(
|
19 | 50 | std::chrono::milliseconds connect_timeout);
|
20 | 51 |
|
| 52 | + /** |
| 53 | + * Set a read timeout. This is the time after the first byte |
| 54 | + * has been received that a read has to complete. |
| 55 | + * |
| 56 | + * @param read_timeout The read timeout. |
| 57 | + * @return A reference to this builder. |
| 58 | + */ |
21 | 59 | HttpPropertiesBuilder& ReadTimeout(std::chrono::milliseconds read_timeout);
|
22 | 60 |
|
| 61 | + /** |
| 62 | + * The time for the first byte to be received during a read. If a byte |
| 63 | + * is not received within this time, then the request will be cancelled. |
| 64 | + * |
| 65 | + * @param response_timeout The response timeout. |
| 66 | + * @return A reference to this builder. |
| 67 | + */ |
| 68 | + HttpPropertiesBuilder& ResponseTimeout( |
| 69 | + std::chrono::milliseconds response_timeout); |
| 70 | + |
| 71 | + /** |
| 72 | + * This should be used for wrapper SDKs to set the wrapper name. |
| 73 | + * |
| 74 | + * Wrapper information will be included in request headers. |
| 75 | + * @param wrapper_name The name of the wrapper. |
| 76 | + * @return A reference to this builder. |
| 77 | + */ |
23 | 78 | HttpPropertiesBuilder& WrapperName(std::string wrapper_name);
|
24 | 79 |
|
| 80 | + /** |
| 81 | + * This should be used for wrapper SDKs to set the wrapper version. |
| 82 | + * |
| 83 | + * Wrapper information will be included in request headers. |
| 84 | + * @param wrapper_version The version of the wrapper. |
| 85 | + * @return A reference to this builder. |
| 86 | + */ |
25 | 87 | HttpPropertiesBuilder& WrapperVersion(std::string wrapper_version);
|
26 | 88 |
|
| 89 | + /** |
| 90 | + * Set all custom headers. This will replace any other customer headers |
| 91 | + * that were set with the Header method, or any previously set |
| 92 | + * headers using the CustomHeaders method. |
| 93 | + * @param base_headers The custom headers. |
| 94 | + * @return A reference to this builder. |
| 95 | + */ |
27 | 96 | HttpPropertiesBuilder& CustomHeaders(
|
28 | 97 | std::map<std::string, std::string> base_headers);
|
29 | 98 |
|
| 99 | + /** |
| 100 | + * Set a custom header value. |
| 101 | + * |
| 102 | + * Calling CustomHeaders will replace any previously set values. |
| 103 | + * @param key The key for the header. |
| 104 | + * @param value The header value. |
| 105 | + * @return A reference to this builder. |
| 106 | + */ |
| 107 | + HttpPropertiesBuilder& Header(std::string key, std::string value); |
| 108 | + |
| 109 | + /** |
| 110 | + * Build a set of HttpProperties. |
| 111 | + * @return The built properties. |
| 112 | + */ |
30 | 113 | [[nodiscard]] built::HttpProperties Build() const;
|
31 | 114 |
|
32 | 115 | private:
|
33 |
| - std::chrono::milliseconds connect_timeout_{}; |
34 |
| - std::chrono::milliseconds read_timeout_{}; |
| 116 | + std::chrono::milliseconds connect_timeout_; |
| 117 | + std::chrono::milliseconds read_timeout_; |
| 118 | + std::chrono::milliseconds response_timeout_; |
35 | 119 | std::string wrapper_name_;
|
36 | 120 | std::string wrapper_version_;
|
37 | 121 | std::map<std::string, std::string> base_headers_;
|
| 122 | + std::string user_agent_; |
38 | 123 | };
|
39 | 124 |
|
40 | 125 | } // namespace launchdarkly::config::detail::builders
|
0 commit comments