32
32
33
33
namespace web
34
34
{
35
- namespace http { namespace client {
36
35
class web_proxy ;
36
+ namespace http { namespace client {
37
37
class http_client_config ;
38
38
}}
39
39
@@ -73,7 +73,7 @@ class credentials
73
73
bool is_set () const { return m_is_set; }
74
74
75
75
private:
76
- friend class web ::http::client:: web_proxy;
76
+ friend class web ::web_proxy;
77
77
friend class web ::http::client::http_client_config;
78
78
friend class web ::experimental::web_sockets::client::websocket_client_config;
79
79
@@ -83,6 +83,88 @@ class credentials
83
83
utility::string_t m_password;
84
84
bool m_is_set;
85
85
};
86
+
87
+ // / <summary>
88
+ // / web_proxy represents the concept of the web proxy, which can be auto-discovered,
89
+ // / disabled, or specified explicitly by the user
90
+ // / </summary>
91
+ class web_proxy
92
+ {
93
+ enum web_proxy_mode_internal{ use_default_, use_auto_discovery_, disabled_, user_provided_ };
94
+ public:
95
+ enum web_proxy_mode{ use_default = use_default_, use_auto_discovery = use_auto_discovery_, disabled = disabled_};
96
+
97
+ // / <summary>
98
+ // / Constructs a proxy with the default settings.
99
+ // / </summary>
100
+ web_proxy () : m_address(_XPLATSTR(" " )), m_mode(use_default_) {}
101
+
102
+ // / <summary>
103
+ // / Creates a proxy with specified mode.
104
+ // / </summary>
105
+ // / <param name="mode">Mode to use.</param>
106
+ web_proxy ( web_proxy_mode mode ) : m_address(_XPLATSTR(" " )), m_mode(static_cast <web_proxy_mode_internal>(mode)) {}
107
+
108
+ // / <summary>
109
+ // / Creates a proxy explicitly with provided address.
110
+ // / </summary>
111
+ // / <param name="address">Proxy URI to use.</param>
112
+ web_proxy ( uri address ) : m_address(address), m_mode(user_provided_) {}
113
+
114
+ // / <summary>
115
+ // / Gets this proxy's URI address. Returns an empty URI if not explicitly set by user.
116
+ // / </summary>
117
+ // / <returns>A reference to this proxy's URI.</returns>
118
+ const uri& address () const { return m_address; }
119
+
120
+ // / <summary>
121
+ // / Gets the credentials used for authentication with this proxy.
122
+ // / </summary>
123
+ // / <returns>Credentials to for this proxy.</returns>
124
+ const web::credentials& credentials () const { return m_credentials; }
125
+
126
+ // / <summary>
127
+ // / Sets the credentials to use for authentication with this proxy.
128
+ // / </summary>
129
+ // / <param name="cred">Credentials to use for this proxy.</param>
130
+ void set_credentials (web::credentials cred) {
131
+ if ( m_mode == disabled_ )
132
+ {
133
+ throw std::invalid_argument (" Cannot attach credentials to a disabled proxy" );
134
+ }
135
+ m_credentials = std::move (cred);
136
+ }
137
+
138
+ // / <summary>
139
+ // / Checks if this proxy was constructed with default settings.
140
+ // / </summary>
141
+ // / <returns>True if default, false otherwise.</param>
142
+ bool is_default () const { return m_mode == use_default_; }
143
+
144
+ // / <summary>
145
+ // / Checks if using a proxy is disabled.
146
+ // / </summary>
147
+ // / <returns>True if disabled, false otherwise.</returns>
148
+ bool is_disabled () const { return m_mode == disabled_; }
149
+
150
+ // / <summary>
151
+ // / Checks if the auto discovery protocol, WPAD, is to be used.
152
+ // / </summary>
153
+ // / <returns>True if auto discovery enabled, false otherwise.</returns>
154
+ bool is_auto_discovery () const { return m_mode == use_auto_discovery_; }
155
+
156
+ // / <summary>
157
+ // / Checks if a proxy address is explicitly specified by the user.
158
+ // / </summary>
159
+ // / <returns>True if a proxy address was explicitly specified, false otherwise.</returns>
160
+ bool is_specified () const { return m_mode == user_provided_; }
161
+
162
+ private:
163
+ uri m_address;
164
+ web_proxy_mode_internal m_mode;
165
+ web::credentials m_credentials;
166
+ };
167
+
86
168
}
87
169
88
- #endif
170
+ #endif
0 commit comments