Skip to content

Commit b7e7aa5

Browse files
committed
Updated the connection and the connection tests.
1 parent bb006d6 commit b7e7aa5

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

http/src/network/http/v2/client/connection/connection.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ namespace network {
7373
* \param read_buffer The buffer in which to read the network data.
7474
* \param callback A callback handler.
7575
*/
76-
virtual void async_read_some(const boost::asio::mutable_buffers_1 &read_buffer,
77-
read_callback callback) = 0;
76+
virtual void async_read_until(boost::asio::streambuf &command_streambuf,
77+
const std::string &delim,
78+
read_callback callback) = 0;
79+
7880

7981
/**
8082
* \brief Cancels an operation on a connection.

http/src/network/http/v2/client/connection/normal_connection.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ namespace network {
4141
boost::asio::async_write(*socket_, command_streambuf, callback);
4242
}
4343

44-
virtual void async_read_some(const boost::asio::mutable_buffers_1 &read_buffer,
45-
read_callback callback) {
46-
socket_->async_read_some(read_buffer, callback);
44+
virtual void async_read_until(boost::asio::streambuf &command_streambuf,
45+
const std::string &delim,
46+
read_callback callback) {
47+
boost::asio::async_read_until(*socket_, command_streambuf, delim, callback);
4748
}
4849

4950
virtual void cancel() {

http/test/v2/features/client/normal_connection_test.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Describe(normal_http_connection) {
2121
resolver_.reset(new tcp::resolver(*io_service_));
2222
connection_.reset(new http::normal_connection(*io_service_));
2323
socket_.reset(new tcp::socket(*io_service_));
24+
//std::memset(response_, 0, sizeof(response_));
2425
}
2526

2627
void TearDown() {
@@ -47,14 +48,13 @@ Describe(normal_http_connection) {
4748
http::request request;
4849
request
4950
.method(http::method::GET)
50-
.path("/")
51+
.path("/LICENSE_1_0.txt")
5152
.version("1.0")
5253
.append_header("Host", "www.boost.org")
5354
.append_header("User-Agent", "normal_connection_test")
5455
.append_header("Connection", "close");
5556

5657
// Write the HTTP request to the socket, sending it to the server.
57-
boost::asio::streambuf request_;
5858
std::ostream request_stream(&request_);
5959
request_stream << request;
6060
connection_->async_write(request_,
@@ -68,13 +68,10 @@ Describe(normal_http_connection) {
6868
void ReadFromBoost(boost::system::error_code &ec,
6969
std::size_t &bytes_read) {
7070
// Read the HTTP response on the socket from the server.
71-
char output[1024];
72-
std::memset(output, 0, sizeof(output));
73-
connection_->async_read_some(boost::asio::mutable_buffers_1(output, sizeof(output)),
74-
[&bytes_read] (const boost::system::error_code &ec_,
75-
std::size_t bytes_read_) {
76-
Assert::That(ec_, Equals(boost::system::error_code()));
77-
bytes_read = bytes_read_;
71+
connection_->async_read_until(response_,
72+
"\r\n",
73+
[] (const boost::system::error_code &ec_, std::size_t) {
74+
Assert::That(ec_, Equals(boost::system::error_code()));
7875
});
7976
}
8077

@@ -100,21 +97,28 @@ Describe(normal_http_connection) {
10097

10198
It(reads_from_boost) {
10299
boost::system::error_code ec;
103-
std::size_t bytes_written = 0, bytes_read = 0;;
100+
std::size_t bytes_written = 0, bytes_read = 0;
104101

105102
ConnectToBoost(ec);
106103
WriteToBoost(ec, bytes_written);
107104
ReadFromBoost(ec, bytes_read);
108105

109106
io_service_->run();
110-
Assert::That(bytes_read, IsGreaterThan(0));
107+
std::istream is(&response_);
108+
std::string status;
109+
std::getline(is, status);
110+
// getline delimits the new line, but not the carriage return
111+
Assert::That(status, Equals("HTTP/1.1 200 OK\r"));
111112
}
112113

113114
std::unique_ptr<boost::asio::io_service> io_service_;
114115
std::unique_ptr<tcp::resolver> resolver_;
115116
std::unique_ptr<http::connection> connection_;
116117
std::unique_ptr<tcp::socket> socket_;
117118

119+
boost::asio::streambuf request_;
120+
boost::asio::streambuf response_;
121+
118122
};
119123

120124
int

0 commit comments

Comments
 (0)