Skip to content

Commit bbc9378

Browse files
author
Valtteri Heikkila
committed
Merge remote-tracking branch 'upstream/development' into cancellation
Conflicts: Release/src/http/client/http_linux.cpp
2 parents b354849 + 5a85cea commit bbc9378

File tree

13 files changed

+128
-131
lines changed

13 files changed

+128
-131
lines changed

Binaries/Debug64/run_tests.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

Binaries/Release64/run_tests.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

Release/include/compat/SafeInt3.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Version 3.0
111111
// For some reason we keep getting compiler errors on OS X/iOS if nullptr isn't
112112
// defined to NULL
113113
#define NEEDS_NULLPTR_DEFINED 1
114-
#elif __has_feature
114+
#elif defined(__has_feature)
115115
#if __has_feature(cxx_nullptr)
116116
#define NEEDS_NULLPTR_DEFINED 0
117117
#else

Release/include/cpprest/http_client_impl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,14 @@ class request_context
142142
/// </summary>
143143
void complete_request(size_t body_size)
144144
{
145-
m_response.set_error_code(0);
146145
m_response._get_impl()->_complete(body_size);
147146

148147
finish();
149148
}
150149

151150
void report_error(unsigned long error_code, const utility::string_t & errorMessage)
152151
{
153-
m_response.set_error_code(error_code);
154-
report_exception(http_exception((int)m_response.error_code(), errorMessage));
152+
report_exception(http_exception((int)error_code, errorMessage));
155153
}
156154

157155
template<typename _ExceptionType>

Release/include/cpprest/http_msg.h

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ class http_msg_base
224224
_ASYNCRTIMP void set_body(concurrency::streams::istream instream, utility::string_t contentType);
225225
_ASYNCRTIMP void set_body(concurrency::streams::istream instream, utility::size64_t contentLength, utility::string_t contentType);
226226

227-
_ASYNCRTIMP utility::string_t _extract_string();
228-
_ASYNCRTIMP json::value _extract_json();
227+
_ASYNCRTIMP utility::string_t _extract_string(bool force = false);
228+
_ASYNCRTIMP json::value _extract_json(bool force = false);
229229
_ASYNCRTIMP std::vector<unsigned char> _extract_vector();
230230

231231
virtual _ASYNCRTIMP utility::string_t to_string() const;
@@ -324,18 +324,14 @@ class _http_server_context
324324
class _http_response : public http::details::http_msg_base
325325
{
326326
public:
327-
_http_response() : m_status_code((std::numeric_limits<uint16_t>::max)()), m_error_code(0) { }
327+
_http_response() : m_status_code((std::numeric_limits<uint16_t>::max)()) { }
328328

329-
_http_response(http::status_code code) : m_status_code(code), m_error_code(0) {}
329+
_http_response(http::status_code code) : m_status_code(code) {}
330330

331331
http::status_code status_code() const { return m_status_code; }
332332

333333
void set_status_code(http::status_code code) { m_status_code = code; }
334334

335-
unsigned long error_code() const { return m_error_code; }
336-
337-
void set_error_code(unsigned long code) { m_error_code = code; }
338-
339335
const http::reason_phrase & reason_phrase() const { return m_reason_phrase; }
340336

341337
void set_reason_phrase(http::reason_phrase reason) { m_reason_phrase = std::move(reason); }
@@ -349,8 +345,6 @@ class _http_response : public http::details::http_msg_base
349345
private:
350346
std::unique_ptr<_http_server_context> m_server_context;
351347

352-
unsigned long m_error_code;
353-
354348
http::status_code m_status_code;
355349
http::reason_phrase m_reason_phrase;
356350
};
@@ -445,22 +439,24 @@ class http_response
445439
/// Extracts the body of the response message as a string value, checking that the content type is a MIME text type.
446440
/// A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
447441
/// </summary>
442+
/// <param name="force">If true, ignores the Content-Type header and assumes UTF-8.</param>
448443
/// <returns>String containing body of the message.</returns>
449-
pplx::task<utility::string_t> extract_string() const
444+
pplx::task<utility::string_t> extract_string(bool force = false) const
450445
{
451446
auto impl = _m_impl;
452-
return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) { return impl->_extract_string(); });
447+
return pplx::create_task(_m_impl->_get_data_available()).then([impl, force](utility::size64_t) { return impl->_extract_string(force); });
453448
}
454449

455450
/// <summary>
456451
/// Extracts the body of the response message into a json value, checking that the content type is application\json.
457452
/// A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
458453
/// </summary>
454+
/// <param name="force">If true, ignores the Content-Type header and assumes UTF-8.</param>
459455
/// <returns>JSON value from the body of this message.</returns>
460-
pplx::task<json::value> extract_json() const
456+
pplx::task<json::value> extract_json(bool force = false) const
461457
{
462458
auto impl = _m_impl;
463-
return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) { return impl->_extract_json(); });
459+
return pplx::create_task(_m_impl->_get_data_available()).then([impl, force](utility::size64_t) { return impl->_extract_json(force); });
464460
}
465461

466462
/// <summary>
@@ -596,18 +592,6 @@ class http_response
596592
return pplx::create_task(impl->_get_data_available()).then([impl](utility::size64_t) -> http_response { return http_response(impl); });
597593
}
598594

599-
/// <summary>
600-
/// Gets the error code of the response. This is used for errors other than HTTP status codes.
601-
/// </summary>
602-
/// <returns>The error code.</returns>
603-
unsigned long error_code() const { return _m_impl->error_code(); }
604-
605-
/// <summary>
606-
/// Sets the error code of the response. This is used for errors other than HTTP status codes.
607-
/// </summary>
608-
/// <param name="code">The error code</param>
609-
void set_error_code(unsigned long code) const { _m_impl->set_error_code(code); }
610-
611595
std::shared_ptr<http::details::_http_response> _get_impl() const { return _m_impl; }
612596

613597
http::details::_http_server_context * _get_server_context() const { return _m_impl->_get_server_context(); }
@@ -620,7 +604,6 @@ class http_response
620604
{
621605
}
622606

623-
private:
624607
std::shared_ptr<http::details::_http_response> _m_impl;
625608
};
626609

@@ -826,22 +809,24 @@ class http_request
826809
/// Extract the body of the request message as a string value, checking that the content type is a MIME text type.
827810
/// A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
828811
/// </summary>
812+
/// <param name="force">If true, ignores the Content-Type header and assumes UTF-8.</param>
829813
/// <returns>String containing body of the message.</returns>
830-
pplx::task<utility::string_t> extract_string()
814+
pplx::task<utility::string_t> extract_string(bool force = false)
831815
{
832816
auto impl = _m_impl;
833-
return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) { return impl->_extract_string(); });
817+
return pplx::create_task(_m_impl->_get_data_available()).then([impl, force](utility::size64_t) { return impl->_extract_string(force); });
834818
}
835819

836820
/// <summary>
837821
/// Extracts the body of the request message into a json value, checking that the content type is application\json.
838822
/// A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
839823
/// </summary>
824+
/// <param name="force">If true, ignores the Content-Type header and assumes UTF-8.</param>
840825
/// <returns>JSON value from the body of this message.</returns>
841-
pplx::task<json::value> extract_json() const
826+
pplx::task<json::value> extract_json(bool force = false) const
842827
{
843828
auto impl = _m_impl;
844-
return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) { return impl->_extract_json(); });
829+
return pplx::create_task(_m_impl->_get_data_available()).then([impl, force](utility::size64_t) { return impl->_extract_json(force); });
845830
}
846831

847832
/// <summary>

Release/include/cpprest/ws_msg.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ namespace details
7070
/// </summary>
7171
enum class websocket_message_type
7272
{
73-
text_fragment,
7473
text_message,
75-
binary_fragment,
7674
binary_message,
7775
close,
7876
ping,
@@ -137,15 +135,6 @@ class websocket_outgoing_message
137135
websocket_outgoing_message()
138136
: _m_impl(std::make_shared<details::_websocket_message>()) {}
139137

140-
/// <summary>
141-
/// Sets a UTF-8 fragment as the message body.
142-
/// </summary>
143-
/// <params>UTF-8 String containing body of the fragment.</returns>
144-
void set_utf8_fragment(std::string data)
145-
{
146-
this->_set_message(std::move(data), websocket_message_type::text_fragment);
147-
}
148-
149138
/// <summary>
150139
/// Sets a UTF-8 message as the message body.
151140
/// </summary>
@@ -155,31 +144,14 @@ class websocket_outgoing_message
155144
this->_set_message(std::move(data), websocket_message_type::text_message);
156145
}
157146

158-
/// <summary>
159-
/// Sets a UTF-8 fragment as the message body.
160-
/// </summary>
161-
/// <params>casablanca input stream representing the body of the fragment.</returns>
162-
void set_utf8_fragment(concurrency::streams::istream istream, size_t len)
163-
{
164-
this->_set_message(istream, len, websocket_message_type::text_fragment);
165-
}
166-
167147
/// <summary>
168148
/// Sets a UTF-8 message as the message body.
169149
/// </summary>
170-
/// <params>casablanca input stream representing the body of the fragment.</returns>
150+
/// <params>casablanca input stream representing the body of the message.</returns>
171151
void set_utf8_message(concurrency::streams::istream istream, size_t len)
172152
{
173153
this->_set_message(istream, len, websocket_message_type::text_message);
174154
}
175-
/// <summary>
176-
/// Sets a binary fragment as the message body.
177-
/// </summary>
178-
/// <params>casablanca input stream representing the body of the fragment.</returns>
179-
void set_binary_fragment(concurrency::streams::istream istream, size_t len)
180-
{
181-
this->_set_message(istream, len, websocket_message_type::binary_fragment);
182-
}
183155

184156
/// <summary>
185157
/// Sets binary data as the message body.

Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ void BlackjackClient::PlayingTable::Refresh()
149149

150150
void BlackjackClient::PlayingTable::InterpretResponse(http_response &response)
151151
{
152-
HRESULT responseHR = response.error_code();
153-
154-
if ( InterpretError(responseHR) || response.headers().content_type() != L"application/json" ) return;
152+
if ( response.headers().content_type() != L"application/json" ) return;
155153

156154
this->resultLabel->Text = L"";
157155

Release/src/http/client/http_linux.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "stdafx.h"
3131

3232
#include "cpprest/http_client_impl.h"
33-
#include <limits>
3433
#include <unordered_set>
3534

3635
using boost::asio::ip::tcp;
@@ -56,6 +55,7 @@ namespace web { namespace http
5655
class linux_connection_pool;
5756
class linux_connection : public std::enable_shared_from_this<linux_connection>
5857
{
58+
friend class linux_connection_pool;
5959
public:
6060
linux_connection(std::weak_ptr<linux_connection_pool> pool_weak, boost::asio::io_service& io_service) :
6161
m_socket(io_service),
@@ -65,8 +65,6 @@ namespace web { namespace http
6565
m_keep_alive(true)
6666
{}
6767

68-
void handle_pool_timer(const boost::system::error_code& ec);
69-
7068
bool close(bool cancel_timer)
7169
{
7270
if (cancel_timer)
@@ -87,6 +85,14 @@ namespace web { namespace http
8785
return !error;
8886
}
8987

88+
bool is_reused() const { return m_is_reused; }
89+
90+
void set_keep_alive(bool keep_alive) { m_keep_alive = keep_alive; }
91+
bool keep_alive() const { return m_keep_alive; }
92+
93+
tcp::socket& socket() { return m_socket; }
94+
95+
private:
9096
template <typename TimeoutHandler>
9197
void start_pool_timer(int timeout_secs, TimeoutHandler handler)
9298
{
@@ -100,14 +106,8 @@ namespace web { namespace http
100106
m_is_reused = true;
101107
}
102108

103-
bool is_reused() const { return m_is_reused; }
104-
105-
bool keep_alive() const { return m_keep_alive; }
106-
void set_keep_alive(bool keep_alive) { m_keep_alive = keep_alive; }
107-
108-
tcp::socket& socket() { return m_socket; }
109+
void handle_pool_timer(const boost::system::error_code& ec);
109110

110-
private:
111111
tcp::socket m_socket;
112112
boost::asio::deadline_timer m_pool_timer;
113113
std::weak_ptr<linux_connection_pool> m_pool_weak;

Release/src/http/common/http_msg.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,24 @@ void http_msg_base::_complete(utility::size64_t body_size, std::exception_ptr ex
196196
}
197197
}
198198

199-
utility::string_t details::http_msg_base::_extract_string()
199+
utility::string_t details::http_msg_base::_extract_string(bool force)
200200
{
201-
utility::string_t content, charset;
202-
parse_content_type_and_charset(headers().content_type(), content, charset);
203-
204-
// If no Content-Type then just return an empty string.
205-
if(content.empty())
201+
utility::string_t content, charset = charset_types::utf8;
202+
if (!force)
206203
{
207-
return utility::string_t();
208-
}
204+
parse_content_type_and_charset(headers().content_type(), content, charset);
209205

210-
// Content-Type must have textual type.
211-
if(!is_content_type_textual(content))
212-
{
213-
throw http_exception(textual_content_type_missing);
206+
// If no Content-Type then just return an empty string.
207+
if (content.empty())
208+
{
209+
return utility::string_t();
210+
}
211+
212+
// Content-Type must have textual type.
213+
if (!is_content_type_textual(content))
214+
{
215+
throw http_exception(textual_content_type_missing);
216+
}
214217
}
215218

216219
if (!instream())
@@ -287,22 +290,25 @@ utility::string_t details::http_msg_base::_extract_string()
287290
}
288291
}
289292

290-
json::value details::http_msg_base::_extract_json()
293+
json::value details::http_msg_base::_extract_json(bool force)
291294
{
292-
utility::string_t content, charset;
293-
parse_content_type_and_charset(headers().content_type(), content, charset);
294-
295-
// If no Content-Type then just return a null json value.
296-
if(content.empty())
295+
utility::string_t content, charset = charset_types::utf8;
296+
if (!force)
297297
{
298-
return json::value();
299-
}
298+
parse_content_type_and_charset(headers().content_type(), content, charset);
300299

301-
// Content-Type must be "application/json" or one of the unofficial, but common JSON types.
302-
if(!is_content_type_json(content))
303-
{
304-
const utility::string_t actualContentType = utility::conversions::to_string_t(content);
305-
throw http_exception((_XPLATSTR("Content-Type must be JSON to extract (is: ") + actualContentType + _XPLATSTR(")")));
300+
// If no Content-Type then just return a null json value.
301+
if (content.empty())
302+
{
303+
return json::value();
304+
}
305+
306+
// Content-Type must be "application/json" or one of the unofficial, but common JSON types.
307+
if (!is_content_type_json(content))
308+
{
309+
const utility::string_t actualContentType = utility::conversions::to_string_t(content);
310+
throw http_exception((_XPLATSTR("Content-Type must be JSON to extract (is: ") + actualContentType + _XPLATSTR(")")));
311+
}
306312
}
307313

308314
if (!instream())

Release/src/websockets/client/ws_msg.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ std::string details::_websocket_message::_extract_string()
8383

8484
pplx::task<std::string> websocket_incoming_message::extract_string() const
8585
{
86-
if (_m_impl->message_type() == websocket_message_type::binary_fragment ||
87-
_m_impl->message_type() == websocket_message_type::binary_message)
86+
if (_m_impl->message_type() == websocket_message_type::binary_message)
8887
{
8988
return pplx::task_from_exception<std::string>(websocket_exception(_XPLATSTR("Invalid message type")));
9089
}

0 commit comments

Comments
 (0)