Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Burninate internal use of ostringstream, and done a ref #905

Merged
merged 3 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Release/include/cpprest/http_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class compress_provider
size_t output_size,
operation_hint hint,
size_t& input_bytes_processed,
bool* done = nullptr) = 0;
bool& done) = 0;
virtual pplx::task<operation_result> compress(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size, operation_hint hint) = 0;
virtual void reset() = 0;
Expand All @@ -71,7 +71,7 @@ class decompress_provider
size_t output_size,
operation_hint hint,
size_t& input_bytes_processed,
bool* done = nullptr) = 0;
bool& done) = 0;
virtual pplx::task<operation_result> decompress(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size, operation_hint hint) = 0;
virtual void reset() = 0;
Expand Down
54 changes: 29 additions & 25 deletions Release/include/cpprest/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,11 @@ namespace json
private:
std::string _message;
public:
json_exception(const utility::char_t * const &message) : _message(utility::conversions::to_utf8string(message)) { }
json_exception(const char * const message) : _message(message) { }
#ifdef _UTF16_STRINGS
json_exception(const wchar_t * const message) : _message(utility::conversions::utf16_to_utf8(message)) { }
#endif // _UTF16_STRINGS
json_exception(std::string&& message) : _message(std::move(message)) { }

// Must be narrow string because it derives from std::exception
const char* what() const CPPREST_NOEXCEPT
Expand Down Expand Up @@ -930,7 +934,7 @@ namespace json
{
if (index >= m_elements.size())
{
throw json_exception(_XPLATSTR("index out of bounds"));
throw json_exception("index out of bounds");
}
m_elements.erase(m_elements.begin() + index);
}
Expand All @@ -943,7 +947,7 @@ namespace json
json::value& at(size_type index)
{
if (index >= m_elements.size())
throw json_exception(_XPLATSTR("index out of bounds"));
throw json_exception("index out of bounds");

return m_elements[index];
}
Expand All @@ -956,7 +960,7 @@ namespace json
const json::value& at(size_type index) const
{
if (index >= m_elements.size())
throw json_exception(_XPLATSTR("index out of bounds"));
throw json_exception("index out of bounds");

return m_elements[index];
}
Expand Down Expand Up @@ -1145,7 +1149,7 @@ namespace json
auto iter = find_by_key(key);
if (iter == m_elements.end())
{
throw web::json::json_exception(_XPLATSTR("Key not found"));
throw web::json::json_exception("Key not found");
}

m_elements.erase(iter);
Expand All @@ -1161,7 +1165,7 @@ namespace json
auto iter = find_by_key(key);
if (iter == m_elements.end())
{
throw web::json::json_exception(_XPLATSTR("Key not found"));
throw web::json::json_exception("Key not found");
}

return iter->second;
Expand All @@ -1177,7 +1181,7 @@ namespace json
auto iter = find_by_key(key);
if (iter == m_elements.end())
{
throw web::json::json_exception(_XPLATSTR("Key not found"));
throw web::json::json_exception("Key not found");
}

return iter->second;
Expand Down Expand Up @@ -1464,14 +1468,14 @@ namespace json
virtual std::unique_ptr<_Value> _copy_value() = 0;

virtual bool has_field(const utility::string_t &) const { return false; }
virtual value get_field(const utility::string_t &) const { throw json_exception(_XPLATSTR("not an object")); }
virtual value get_element(array::size_type) const { throw json_exception(_XPLATSTR("not an array")); }
virtual value get_field(const utility::string_t &) const { throw json_exception("not an object"); }
virtual value get_element(array::size_type) const { throw json_exception("not an array"); }

virtual value &index(const utility::string_t &) { throw json_exception(_XPLATSTR("not an object")); }
virtual value &index(array::size_type) { throw json_exception(_XPLATSTR("not an array")); }
virtual value &index(const utility::string_t &) { throw json_exception("not an object"); }
virtual value &index(array::size_type) { throw json_exception("not an array"); }

virtual const value &cnst_index(const utility::string_t &) const { throw json_exception(_XPLATSTR("not an object")); }
virtual const value &cnst_index(array::size_type) const { throw json_exception(_XPLATSTR("not an array")); }
virtual const value &cnst_index(const utility::string_t &) const { throw json_exception("not an object"); }
virtual const value &cnst_index(array::size_type) const { throw json_exception("not an array"); }

// Common function used for serialization to strings and streams.
virtual void serialize_impl(std::string& str) const
Expand All @@ -1494,18 +1498,18 @@ namespace json

virtual json::value::value_type type() const { return json::value::Null; }

virtual bool is_integer() const { throw json_exception(_XPLATSTR("not a number")); }
virtual bool is_double() const { throw json_exception(_XPLATSTR("not a number")); }

virtual const json::number& as_number() { throw json_exception(_XPLATSTR("not a number")); }
virtual double as_double() const { throw json_exception(_XPLATSTR("not a number")); }
virtual int as_integer() const { throw json_exception(_XPLATSTR("not a number")); }
virtual bool as_bool() const { throw json_exception(_XPLATSTR("not a boolean")); }
virtual json::array& as_array() { throw json_exception(_XPLATSTR("not an array")); }
virtual const json::array& as_array() const { throw json_exception(_XPLATSTR("not an array")); }
virtual json::object& as_object() { throw json_exception(_XPLATSTR("not an object")); }
virtual const json::object& as_object() const { throw json_exception(_XPLATSTR("not an object")); }
virtual const utility::string_t& as_string() const { throw json_exception(_XPLATSTR("not a string")); }
virtual bool is_integer() const { throw json_exception("not a number"); }
virtual bool is_double() const { throw json_exception("not a number"); }

virtual const json::number& as_number() { throw json_exception("not a number"); }
virtual double as_double() const { throw json_exception("not a number"); }
virtual int as_integer() const { throw json_exception("not a number"); }
virtual bool as_bool() const { throw json_exception("not a boolean"); }
virtual json::array& as_array() { throw json_exception("not an array"); }
virtual const json::array& as_array() const { throw json_exception("not an array"); }
virtual json::object& as_object() { throw json_exception("not an object"); }
virtual const json::object& as_object() const { throw json_exception("not an object"); }
virtual const utility::string_t& as_string() const { throw json_exception("not a string"); }

virtual size_t size() const { return 0; }

Expand Down
6 changes: 3 additions & 3 deletions Release/src/http/client/http_client_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ class asio_context final : public request_context, public std::enable_shared_fro
m_response.set_status_code(status_code);

::web::http::details::trim_whitespace(status_message);
m_response.set_reason_phrase(utility::conversions::to_string_t(std::move(status_message)));
m_response.set_reason_phrase(utility::conversions::details::to_string_t(std::move(status_message)));

if (!response_stream || http_version.substr(0, 5) != "HTTP/")
{
Expand Down Expand Up @@ -1406,8 +1406,8 @@ class asio_context final : public request_context, public std::enable_shared_fro
m_connection->set_keep_alive(!boost::iequals(value, U("close")));
}

m_response.headers().add(utility::conversions::to_string_t(std::move(name)),
utility::conversions::to_string_t(std::move(value)));
m_response.headers().add(utility::conversions::details::to_string_t(std::move(name)),
utility::conversions::details::to_string_t(std::move(value)));
}
}

Expand Down
41 changes: 27 additions & 14 deletions Release/src/http/client/http_client_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
****/
#include "stdafx.h"
#include "../common/internal_http_helpers.h"
#include "cpprest/asyncrt_utils.h"

namespace web { namespace http
{
Expand Down Expand Up @@ -61,29 +62,41 @@ void details::_http_request::set_request_uri(const uri& relative)

utility::string_t details::_http_request::to_string() const
{
utility::ostringstream_t buffer;
buffer.imbue(std::locale::classic());
buffer << m_method << _XPLATSTR(" ") << (this->m_uri.is_empty() ? _XPLATSTR("/") : this->m_uri.to_string()) << _XPLATSTR(" HTTP/1.1\r\n");
buffer << http_msg_base::to_string();
return buffer.str();
utility::string_t result(m_method);
result += _XPLATSTR(' ');
if (this->m_uri.is_empty())
{
result += _XPLATSTR('/');
}
else
{
result += this->m_uri.to_string();
}

result += _XPLATSTR(" HTTP/1.1\r\n");
result += http_msg_base::to_string();
return result;
}

utility::string_t details::_http_response::to_string() const
{
utility::string_t result(_XPLATSTR("HTTP/1.1 "));
result += utility::conversions::details::to_string_t(m_status_code);
result += ' ';
// If the user didn't explicitly set a reason phrase then we should have it default
// if they used one of the standard known status codes.
auto reason_phrase = m_reason_phrase;
if(reason_phrase.empty())
if (m_reason_phrase.empty())
{
reason_phrase = get_default_reason_phrase(status_code());
result += get_default_reason_phrase(status_code());
}
else
{
result += m_reason_phrase;
}

utility::ostringstream_t buffer;
buffer.imbue(std::locale::classic());
buffer << _XPLATSTR("HTTP/1.1 ") << m_status_code << _XPLATSTR(" ") << reason_phrase << _XPLATSTR("\r\n");

buffer << http_msg_base::to_string();
return buffer.str();
result += _XPLATSTR("\r\n");
result += http_msg_base::to_string();
return result;
}

}} // namespace web::http
3 changes: 2 additions & 1 deletion Release/src/http/client/http_client_winrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class HttpRequestCallback final :
std::wstring msg(L"IXMLHttpRequest2Callback::OnError: ");
msg.append(std::to_wstring(hrError));
msg.append(L": ");
msg.append(utility::conversions::to_string_t(utility::details::windows_category().message(hrError)));
msg.append(utility::conversions::details::to_string_t(
utility::details::windows_category().message(hrError)));
m_request->report_error(hrError, msg);
}
else
Expand Down
Loading