Skip to content

Commit 7ced174

Browse files
committed
Fixing up a few issues with misc http improvements:
1. Can use using alias since not support with VS2012. 2. Fixed a couple of failing listener tests on Linux.
1 parent 2598857 commit 7ced174

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

Release/include/cpprest/basic_types.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ typedef std::stringstream stringstream_t;
100100

101101
}// namespace utility
102102

103-
using utf8char = char;
104-
using utf8string = std::string;
105-
using utf8stringstream = std::stringstream;
106-
using utf8ostringstream = std::ostringstream;
107-
using utf8ostream = std::ostream;
108-
using utf8istream = std::istream;
109-
using utf8istringstream = std::istringstream;
103+
typedef char utf8char;
104+
typedef std::string utf8string;
105+
typedef std::stringstream utf8stringstream;
106+
typedef std::ostringstream utf8ostringstream;
107+
typedef std::ostream utf8ostream;
108+
typedef std::istream utf8istream;
109+
typedef std::istringstream utf8istringstream;
110110

111111
#ifdef _UTF16_STRINGS
112112
typedef wchar_t utf16char;

Release/include/cpprest/http_msg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ class http_request
10851085
// Callers of this function do NOT need to block waiting for the response to be
10861086
/// sent to before the body data is destroyed or goes out of scope.
10871087
/// </remarks>
1088-
pplx::task<void> reply(http::status_code status, utf8string &&body_data, const utf8string &content_type = "text/plain") const
1088+
pplx::task<void> reply(http::status_code status, utf8string &&body_data, const utf8string &content_type = "text/plain; charset=utf-8") const
10891089
{
10901090
http_response response(status);
10911091
response.set_body(std::move(body_data), content_type);
@@ -1104,7 +1104,7 @@ class http_request
11041104
// Callers of this function do NOT need to block waiting for the response to be
11051105
/// sent to before the body data is destroyed or goes out of scope.
11061106
/// </remarks>
1107-
pplx::task<void> reply(http::status_code status, const utf8string &body_data, const utf8string &content_type = "text/plain") const
1107+
pplx::task<void> reply(http::status_code status, const utf8string &body_data, const utf8string &content_type = "text/plain; charset=utf-8") const
11081108
{
11091109
http_response response(status);
11101110
response.set_body(body_data, content_type);

Release/tests/functional/http/listener/building_response_tests.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ TEST_FIXTURE(uri_address, set_body_with_content_type)
4444
VERIFY_ARE_EQUAL(0u, p_client->request(methods::POST, U("")));
4545
p_client->next_response().then([&](test_response *p_response)
4646
{
47-
http_asserts::assert_test_response_equals(p_response, status_codes::OK, U("text; charset=utf-8"), U("test string"));
47+
#ifdef _UTF16_STRINGS
48+
const ::utility::string_t expectedContentType(U("text; charset=utf-8"));
49+
#else
50+
const ::utility::string_t expectedContentType(U("text"));
51+
#endif
52+
http_asserts::assert_test_response_equals(p_response, status_codes::OK, expectedContentType, U("test string"));
4853
}).wait();
4954

5055
listener.close().wait();
@@ -100,7 +105,9 @@ TEST_FIXTURE(uri_address, set_body_string)
100105
TEST(set_body_string_with_charset)
101106
{
102107
http_response response;
103-
VERIFY_THROWS(response.set_body(U("body_data"), U("text/plain;charset=utf-16")), std::invalid_argument);
108+
VERIFY_THROWS(response.set_body(
109+
::utility::conversions::to_utf16string("body_data"),
110+
::utility::conversions::to_utf16string("text/plain;charset=utf-16")), std::invalid_argument);
104111
}
105112

106113
TEST_FIXTURE(uri_address, set_body_vector)

Release/tests/functional/http/listener/connections_and_errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ TEST_FIXTURE(uri_address, send_response_later)
108108
});
109109
VERIFY_ARE_EQUAL(0, p_client->request(methods::POST, U("")));
110110
request_event.wait();
111-
requests[0].reply(status_codes::OK, U("HEHEHE")).wait();
111+
requests[0].reply(status_codes::OK, "HEHEHE").wait();
112112
requests.clear();
113113
p_client->next_response().then([&](test_response *p_response)
114114
{

Release/tests/functional/http/listener/reply_helper_tests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ TEST_FIXTURE(uri_address, string)
5656

5757
listener.support([](http_request request)
5858
{
59-
request.reply(status_codes::OK, U("test str")).wait();
59+
std::string body("test str");
60+
request.reply(status_codes::OK, body).wait();
6061
});
6162
VERIFY_ARE_EQUAL(0, p_client->request(methods::POST, U("")));
6263
p_client->next_response().then([&](test_response *p_response)
@@ -76,10 +77,10 @@ TEST_FIXTURE(uri_address, string)
7677
http_asserts::assert_test_response_equals(p_response, status_codes::OK, U("custom content"), U("test str"));
7778
}).wait();
7879

79-
// content type and move string body
80+
// content type and rvalue reference string body
8081
listener.support([](http_request request)
8182
{
82-
request.reply(status_codes::OK, std::move(utility::string_t(U("test str"))), U("text/plain")).wait();
83+
request.reply(status_codes::OK, "test str", "text/plain").wait();
8384
});
8485
VERIFY_ARE_EQUAL(0, p_client->request(methods::POST, U("")));
8586
p_client->next_response().then([&](test_response *p_response)

0 commit comments

Comments
 (0)