Skip to content

Commit d9e5331

Browse files
committed
Merge branch 'development' of https://git01.codeplex.com/casablanca into websocket_tls
Conflicts: Release/include/cpprest/ws_msg.h
2 parents 3846888 + 6255edf commit d9e5331

24 files changed

+717
-166
lines changed

CONTRIBUTORS.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ Michael M (M1xa)
1111
Matt Peterson (MattPeterson1)
1212
Dmitry Kolomiets (kolomiets)
1313

14-
14+
Illumina Inc.
15+
Gery Vessere ([email protected])

Release/include/cpprest/base_uri.h

Lines changed: 121 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,61 @@
4040
namespace web {
4141
namespace details
4242
{
43-
struct _uri_components
43+
struct uri_components
4444
{
45-
_uri_components()
45+
uri_components() : m_path(_XPLATSTR("/")), m_port(-1)
46+
{}
47+
48+
uri_components(const uri_components &other) :
49+
m_scheme(other.m_scheme),
50+
m_host(other.m_host),
51+
m_user_info(other.m_user_info),
52+
m_path(other.m_path),
53+
m_query(other.m_query),
54+
m_fragment(other.m_fragment),
55+
m_port(other.m_port)
56+
{}
57+
58+
uri_components & operator=(const uri_components &other)
4659
{
47-
m_path = _XPLATSTR("/");
48-
m_port = -1;
60+
if (this != &other)
61+
{
62+
m_scheme = other.m_scheme;
63+
m_host = other.m_host;
64+
m_user_info = other.m_user_info;
65+
m_path = other.m_path;
66+
m_query = other.m_query;
67+
m_fragment = other.m_fragment;
68+
m_port = other.m_port;
69+
}
70+
return *this;
4971
}
5072

73+
uri_components(uri_components &&other) _noexcept :
74+
m_scheme(std::move(other.m_scheme)),
75+
m_host(std::move(other.m_host)),
76+
m_user_info(std::move(other.m_user_info)),
77+
m_path(std::move(other.m_path)),
78+
m_query(std::move(other.m_query)),
79+
m_fragment(std::move(other.m_fragment)),
80+
m_port(other.m_port)
81+
{}
82+
83+
uri_components & operator=(uri_components &&other) _noexcept
84+
{
85+
if (this != &other)
86+
{
87+
m_scheme = std::move(other.m_scheme);
88+
m_host = std::move(other.m_host);
89+
m_user_info = std::move(other.m_user_info);
90+
m_path = std::move(other.m_path);
91+
m_query = std::move(other.m_query);
92+
m_fragment = std::move(other.m_fragment);
93+
m_port = other.m_port;
94+
}
95+
return *this;
96+
}
97+
5198
_ASYNCRTIMP utility::string_t join();
5299

53100
utility::string_t m_scheme;
@@ -81,25 +128,25 @@ namespace web {
81128
};
82129

83130
/// <summary>
84-
/// A flexible, protocol independent uri implementation.
131+
/// A flexible, protocol independent URI implementation.
85132
///
86-
/// URI instances are immutable. Querying the various fields on an emtpy uri will return empty strings. Querying
87-
/// various diagnostic members on an empty uri will return false.
133+
/// URI instances are immutable. Querying the various fields on an emtpy URI will return empty strings. Querying
134+
/// various diagnostic members on an empty URI will return false.
88135
/// </summary>
89136
/// <remarks>
90-
/// This implementation accepts both uris ('http://msn.com/path') and uri relative-references
137+
/// This implementation accepts both URIs ('http://msn.com/path') and URI relative-references
91138
/// ('/path?query#frag').
92139
///
93140
/// This implementation does not provide any scheme-specific handling -- an example of this
94-
/// would be the following: 'http://path1/path'. This is a valid uri, but it's not a valid
141+
/// would be the following: 'http://path1/path'. This is a valid URI, but it's not a valid
95142
/// http-uri -- that is, it's syntactically correct but does not conform to the requirements
96143
/// of the http scheme (http requires a host).
97144
/// We could provide this by allowing a pluggable 'scheme' policy-class, which would provide
98-
/// extra capability for validating and canonicalizing a uri according to scheme, and would
99-
/// introduce a layer of type-safety for uris of differing schemes, and thus differing semantics.
145+
/// extra capability for validating and canonicalizing a URI according to scheme, and would
146+
/// introduce a layer of type-safety for URIs of differing schemes, and thus differing semantics.
100147
///
101-
/// One issue with implementing a scheme-independent uri facility is that of comparing for equality.
102-
/// For instance, these uris are considered equal 'http://msn.com', 'http://msn.com:80'. That is --
148+
/// One issue with implementing a scheme-independent URI facility is that of comparing for equality.
149+
/// For instance, these URIs are considered equal 'http://msn.com', 'http://msn.com:80'. That is --
103150
/// the 'default' port can be either omitted or explicit. Since we don't have a way to map a scheme
104151
/// to it's default port, we don't have a way to know these are equal. This is just one of a class of
105152
/// issues with regard to scheme-specific behavior.
@@ -168,9 +215,9 @@ namespace web {
168215
_ASYNCRTIMP static std::map<utility::string_t, utility::string_t> __cdecl split_query(const utility::string_t &query);
169216

170217
/// <summary>
171-
/// Validates a string as a uri.
218+
/// Validates a string as a URI.
172219
/// </summary>
173-
/// <param name="uri_string">The uri string to be validated.</param>
220+
/// <param name="uri_string">The URI string to be validated.</param>
174221
/// <returns><c>true</c> if the given string represents a valid URI, <c>false</c> otherwise.</returns>
175222
_ASYNCRTIMP static bool __cdecl validate(const utility::string_t &uri_string);
176223

@@ -180,19 +227,61 @@ namespace web {
180227
uri() { m_uri = _XPLATSTR("/");};
181228

182229
/// <summary>
183-
/// Creates a uri from the given encoded string. This will throw an exception if the string
184-
/// does not contain a valid uri. Use uri::validate if processing user-input.
230+
/// Creates a URI from the given encoded string. This will throw an exception if the string
231+
/// does not contain a valid URI. Use uri::validate if processing user-input.
185232
/// </summary>
186233
/// <param name="uri_string">A pointer to an encoded string to create the URI instance.</param>
187234
_ASYNCRTIMP uri(const utility::char_t *uri_string);
188235

189236
/// <summary>
190-
/// Creates a uri from the given encoded string. This will throw an exception if the string
191-
/// does not contain a valid uri. Use uri::validate if processing user-input.
237+
/// Creates a URI from the given encoded string. This will throw an exception if the string
238+
/// does not contain a valid URI. Use uri::validate if processing user-input.
192239
/// </summary>
193-
/// <param name="uri_string">An encoded uri string to create the URI instance.</param>
240+
/// <param name="uri_string">An encoded URI string to create the URI instance.</param>
194241
_ASYNCRTIMP uri(const utility::string_t &uri_string);
195242

243+
/// <summary>
244+
/// Copy constructor.
245+
/// </summary>
246+
uri(const uri &other) :
247+
m_uri(other.m_uri),
248+
m_components(other.m_components)
249+
{}
250+
251+
/// <summary>
252+
/// Copy assignment operator.
253+
/// </summary>
254+
uri & operator=(const uri &other)
255+
{
256+
if (this != &other)
257+
{
258+
m_uri = other.m_uri;
259+
m_components = other.m_components;
260+
}
261+
return *this;
262+
}
263+
264+
/// <summary>
265+
/// Move constructor.
266+
/// </summary>
267+
uri(uri &&other) _noexcept :
268+
m_uri(std::move(other.m_uri)),
269+
m_components(std::move(other.m_components))
270+
{}
271+
272+
/// <summary>
273+
/// Move assignment operator
274+
/// </summary>
275+
uri & operator=(uri &&other) _noexcept
276+
{
277+
if (this != &other)
278+
{
279+
m_uri = std::move(other.m_uri);
280+
m_components = std::move(other.m_components);
281+
}
282+
return *this;
283+
}
284+
196285
/// <summary>
197286
/// Get the scheme component of the URI as an encoded string.
198287
/// </summary>
@@ -244,11 +333,11 @@ namespace web {
244333
/// <summary>
245334
/// Gets the path, query, and fragment portion of this uri, which may be empty.
246335
/// </summary>
247-
/// <returns>The new uri object with the path, query and fragment portion of this uri.</returns>
336+
/// <returns>The new URI object with the path, query and fragment portion of this URI.</returns>
248337
_ASYNCRTIMP uri resource() const;
249338

250339
/// <summary>
251-
/// An empty uri specifies no components, and serves as a default value
340+
/// An empty URI specifies no components, and serves as a default value
252341
/// </summary>
253342
bool is_empty() const
254343
{
@@ -303,37 +392,37 @@ namespace web {
303392
}
304393

305394
/// <summary>
306-
/// An "authority" uri is one with only a scheme, optional userinfo, hostname, and (optional) port.
395+
/// An "authority" URI is one with only a scheme, optional userinfo, hostname, and (optional) port.
307396
/// </summary>
308-
/// <returns><c>true</c> if this is an "authority" uri, <c>false</c> otherwise.</returns>
397+
/// <returns><c>true</c> if this is an "authority" URI, <c>false</c> otherwise.</returns>
309398
bool is_authority() const
310399
{
311400
return !is_empty() && is_path_empty() && query().empty() && fragment().empty();
312401
}
313402

314403
/// <summary>
315-
/// Returns whether the other uri has the same authority as this one
404+
/// Returns whether the other URI has the same authority as this one
316405
/// </summary>
317-
/// <param name="other">The uri to compare the authority with.</param>
318-
/// <returns><c>true</c> if both the uri's have the same authority, <c>false</c> otherwise.</returns>
406+
/// <param name="other">The URI to compare the authority with.</param>
407+
/// <returns><c>true</c> if both the URI's have the same authority, <c>false</c> otherwise.</returns>
319408
bool has_same_authority(const uri &other) const
320409
{
321410
return !is_empty() && this->authority() == other.authority();
322411
}
323412

324413
/// <summary>
325-
/// Returns whether the path portion of this uri is empty
414+
/// Returns whether the path portion of this URI is empty
326415
/// </summary>
327-
/// <returns><c>true</c> if the path portion of this uri is empty, <c>false</c> otherwise.</returns>
416+
/// <returns><c>true</c> if the path portion of this URI is empty, <c>false</c> otherwise.</returns>
328417
bool is_path_empty() const
329418
{
330419
return path().empty() || path() == _XPLATSTR("/");
331420
}
332421

333422
/// <summary>
334-
/// Returns the full (encoded) uri as a string.
423+
/// Returns the full (encoded) URI as a string.
335424
/// </summary>
336-
/// <returns>The full encoded uri string.</returns>
425+
/// <returns>The full encoded URI string.</returns>
337426
utility::string_t to_string() const
338427
{
339428
return m_uri;
@@ -358,7 +447,7 @@ namespace web {
358447
static utility::string_t encode_impl(const utility::string_t &raw, const std::function<bool(int)>& should_encode);
359448

360449
utility::string_t m_uri;
361-
details::_uri_components m_components;
450+
details::uri_components m_components;
362451
};
363452

364453
} // namespace web

Release/include/cpprest/http_client.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ class http_client_config
163163
/// Set the web proxy object
164164
/// </summary>
165165
/// <param name="proxy">A reference to the web proxy object.</param>
166-
void set_proxy(const web_proxy& proxy)
166+
void set_proxy(web_proxy proxy)
167167
{
168-
m_proxy = proxy;
168+
m_proxy = std::move(proxy);
169169
}
170170

171171
/// <summary>
@@ -377,10 +377,7 @@ class http_client
377377
/// <returns>
378378
/// A base uri initialized in constructor
379379
/// </return>
380-
const uri& base_uri() const
381-
{
382-
return _base_uri;
383-
}
380+
_ASYNCRTIMP const uri& base_uri() const;
384381

385382
/// <summary>
386383
/// Get client configuration object
@@ -394,7 +391,7 @@ class http_client
394391
/// <param name="handler">A function object representing the pipeline stage.</param>
395392
void add_handler(std::function<pplx::task<http_response>(http_request, std::shared_ptr<http::http_pipeline_stage>)> handler)
396393
{
397-
m_pipeline->append(std::make_shared< ::web::http::details::function_pipeline_wrapper>(handler));
394+
m_pipeline->append(std::make_shared<::web::http::details::function_pipeline_wrapper>(handler));
398395
}
399396

400397
/// <summary>
@@ -593,8 +590,6 @@ class http_client
593590
void build_pipeline(uri base_uri, http_client_config client_config);
594591

595592
std::shared_ptr<::web::http::http_pipeline> m_pipeline;
596-
597-
uri _base_uri;
598593
};
599594

600595
}}} // namespaces

Release/include/cpprest/http_client_impl.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ class _http_client_communicator
299299
return m_client_config;
300300
}
301301

302+
const uri & base_uri() const
303+
{
304+
return m_uri;
305+
}
306+
302307
protected:
303308
_http_client_communicator(http::uri address, http_client_config client_config)
304309
: m_uri(std::move(address)), m_client_config(std::move(client_config)), m_opened(false), m_scheduled(0)
@@ -437,15 +442,13 @@ void verify_uri(const uri &uri)
437442
} // namespace details
438443

439444
http_client::http_client(uri base_uri)
440-
:_base_uri(std::move(base_uri))
441445
{
442-
build_pipeline(_base_uri, http_client_config());
446+
build_pipeline(std::move(base_uri), http_client_config());
443447
}
444448

445449
http_client::http_client(uri base_uri, http_client_config client_config)
446-
:_base_uri(std::move(base_uri))
447450
{
448-
build_pipeline(_base_uri, std::move(client_config));
451+
build_pipeline(std::move(base_uri), std::move(client_config));
449452
}
450453

451454
void http_client::build_pipeline(uri base_uri, http_client_config client_config)
@@ -458,26 +461,27 @@ void http_client::build_pipeline(uri base_uri, http_client_config client_config)
458461
}
459462
details::verify_uri(base_uri);
460463

461-
std::vector<std::shared_ptr<http::http_pipeline_stage> > extra_handlers;
464+
m_pipeline = ::web::http::http_pipeline::create_pipeline(std::make_shared<details::http_network_handler>(std::move(base_uri), std::move(client_config)));
462465

463466
#if !defined(CPPREST_TARGET_XP) && !defined(_PHONE8_)
464-
extra_handlers.push_back(std::make_shared<oauth1::details::oauth1_handler>(client_config.oauth1()));
467+
add_handler(std::static_pointer_cast<http::http_pipeline_stage>(
468+
std::make_shared<oauth1::details::oauth1_handler>(this->client_config().oauth1())));
465469
#endif // !defined(CPPREST_TARGET_XP) && !defined(_PHONE8_)
466470

467-
extra_handlers.push_back(std::make_shared<oauth2::details::oauth2_handler>(client_config.oauth2()));
468-
469-
m_pipeline = ::web::http::http_pipeline::create_pipeline(std::make_shared<details::http_network_handler>(std::move(base_uri), std::move(client_config)));
470-
471-
for (auto& handler : extra_handlers)
472-
{
473-
add_handler(handler);
474-
}
471+
add_handler(std::static_pointer_cast<http::http_pipeline_stage>(
472+
std::make_shared<oauth2::details::oauth2_handler>(this->client_config().oauth2())));
475473
}
476474

477-
const http_client_config& http_client::client_config() const
475+
const http_client_config & http_client::client_config() const
478476
{
479-
auto* ph = static_cast<details::http_network_handler*>(m_pipeline->last_stage().get());
477+
auto ph = std::static_pointer_cast<details::http_network_handler>(m_pipeline->last_stage());
480478
return ph->http_client_impl()->client_config();
481479
}
482480

481+
const uri & http_client::base_uri() const
482+
{
483+
auto ph = std::static_pointer_cast<details::http_network_handler>(m_pipeline->last_stage());
484+
return ph->http_client_impl()->base_uri();
485+
}
486+
483487
}}} // namespaces

0 commit comments

Comments
 (0)