Skip to content

Commit c6b6450

Browse files
committed
Adding some copy constructors and updating some comments.
1 parent 6a52f3d commit c6b6450

File tree

2 files changed

+75
-29
lines changed

2 files changed

+75
-29
lines changed

Release/include/cpprest/base_uri.h

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ namespace web {
4545
uri_components() : m_path(_XPLATSTR("/")), m_port(-1)
4646
{}
4747

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)
59+
{
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;
71+
}
72+
4873
uri_components(uri_components &&other) _noexcept :
4974
m_scheme(std::move(other.m_scheme)),
5075
m_host(std::move(other.m_host)),
@@ -103,25 +128,25 @@ namespace web {
103128
};
104129

105130
/// <summary>
106-
/// A flexible, protocol independent uri implementation.
131+
/// A flexible, protocol independent URI implementation.
107132
///
108-
/// URI instances are immutable. Querying the various fields on an emtpy uri will return empty strings. Querying
109-
/// 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.
110135
/// </summary>
111136
/// <remarks>
112-
/// 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
113138
/// ('/path?query#frag').
114139
///
115140
/// This implementation does not provide any scheme-specific handling -- an example of this
116-
/// 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
117142
/// http-uri -- that is, it's syntactically correct but does not conform to the requirements
118143
/// of the http scheme (http requires a host).
119144
/// We could provide this by allowing a pluggable 'scheme' policy-class, which would provide
120-
/// extra capability for validating and canonicalizing a uri according to scheme, and would
121-
/// 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.
122147
///
123-
/// One issue with implementing a scheme-independent uri facility is that of comparing for equality.
124-
/// 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 --
125150
/// the 'default' port can be either omitted or explicit. Since we don't have a way to map a scheme
126151
/// to it's default port, we don't have a way to know these are equal. This is just one of a class of
127152
/// issues with regard to scheme-specific behavior.
@@ -190,9 +215,9 @@ namespace web {
190215
_ASYNCRTIMP static std::map<utility::string_t, utility::string_t> __cdecl split_query(const utility::string_t &query);
191216

192217
/// <summary>
193-
/// Validates a string as a uri.
218+
/// Validates a string as a URI.
194219
/// </summary>
195-
/// <param name="uri_string">The uri string to be validated.</param>
220+
/// <param name="uri_string">The URI string to be validated.</param>
196221
/// <returns><c>true</c> if the given string represents a valid URI, <c>false</c> otherwise.</returns>
197222
_ASYNCRTIMP static bool __cdecl validate(const utility::string_t &uri_string);
198223

@@ -202,19 +227,40 @@ namespace web {
202227
uri() { m_uri = _XPLATSTR("/");};
203228

204229
/// <summary>
205-
/// Creates a uri from the given encoded string. This will throw an exception if the string
206-
/// 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.
207232
/// </summary>
208233
/// <param name="uri_string">A pointer to an encoded string to create the URI instance.</param>
209234
_ASYNCRTIMP uri(const utility::char_t *uri_string);
210235

211236
/// <summary>
212-
/// Creates a uri from the given encoded string. This will throw an exception if the string
213-
/// 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.
214239
/// </summary>
215-
/// <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>
216241
_ASYNCRTIMP uri(const utility::string_t &uri_string);
217242

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+
218264
/// <summary>
219265
/// Move constructor.
220266
/// </summary>
@@ -287,11 +333,11 @@ namespace web {
287333
/// <summary>
288334
/// Gets the path, query, and fragment portion of this uri, which may be empty.
289335
/// </summary>
290-
/// <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>
291337
_ASYNCRTIMP uri resource() const;
292338

293339
/// <summary>
294-
/// 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
295341
/// </summary>
296342
bool is_empty() const
297343
{
@@ -346,37 +392,37 @@ namespace web {
346392
}
347393

348394
/// <summary>
349-
/// 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.
350396
/// </summary>
351-
/// <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>
352398
bool is_authority() const
353399
{
354400
return !is_empty() && is_path_empty() && query().empty() && fragment().empty();
355401
}
356402

357403
/// <summary>
358-
/// 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
359405
/// </summary>
360-
/// <param name="other">The uri to compare the authority with.</param>
361-
/// <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>
362408
bool has_same_authority(const uri &other) const
363409
{
364410
return !is_empty() && this->authority() == other.authority();
365411
}
366412

367413
/// <summary>
368-
/// Returns whether the path portion of this uri is empty
414+
/// Returns whether the path portion of this URI is empty
369415
/// </summary>
370-
/// <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>
371417
bool is_path_empty() const
372418
{
373419
return path().empty() || path() == _XPLATSTR("/");
374420
}
375421

376422
/// <summary>
377-
/// Returns the full (encoded) uri as a string.
423+
/// Returns the full (encoded) URI as a string.
378424
/// </summary>
379-
/// <returns>The full encoded uri string.</returns>
425+
/// <returns>The full encoded URI string.</returns>
380426
utility::string_t to_string() const
381427
{
382428
return m_uri;

Release/include/cpprest/http_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,13 @@ class http_client
377377
/// <returns>
378378
/// A base uri initialized in constructor
379379
/// </return>
380-
const uri& base_uri() const;
380+
_ASYNCRTIMP const uri& base_uri() const;
381381

382382
/// <summary>
383383
/// Get client configuration object
384384
/// </summary>
385385
/// <returns>A reference to the client configuration object.</returns>
386-
const http_client_config& client_config() const;
386+
_ASYNCRTIMP const http_client_config& client_config() const;
387387

388388
/// <summary>
389389
/// Adds an HTTP pipeline stage to the client.

0 commit comments

Comments
 (0)