@@ -21,6 +21,7 @@ Describe(normal_http_connection) {
21
21
resolver_.reset (new tcp::resolver (*io_service_));
22
22
connection_.reset (new http::normal_connection (*io_service_));
23
23
socket_.reset (new tcp::socket (*io_service_));
24
+ // std::memset(response_, 0, sizeof(response_));
24
25
}
25
26
26
27
void TearDown () {
@@ -47,14 +48,13 @@ Describe(normal_http_connection) {
47
48
http::request request;
48
49
request
49
50
.method (http::method::GET)
50
- .path (" /" )
51
+ .path (" /LICENSE_1_0.txt " )
51
52
.version (" 1.0" )
52
53
.append_header (" Host" , " www.boost.org" )
53
54
.append_header (" User-Agent" , " normal_connection_test" )
54
55
.append_header (" Connection" , " close" );
55
56
56
57
// Write the HTTP request to the socket, sending it to the server.
57
- boost::asio::streambuf request_;
58
58
std::ostream request_stream (&request_);
59
59
request_stream << request;
60
60
connection_->async_write (request_,
@@ -68,13 +68,10 @@ Describe(normal_http_connection) {
68
68
void ReadFromBoost (boost::system::error_code &ec,
69
69
std::size_t &bytes_read) {
70
70
// 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 ()));
78
75
});
79
76
}
80
77
@@ -100,21 +97,28 @@ Describe(normal_http_connection) {
100
97
101
98
It (reads_from_boost) {
102
99
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 ;
104
101
105
102
ConnectToBoost (ec);
106
103
WriteToBoost (ec, bytes_written);
107
104
ReadFromBoost (ec, bytes_read);
108
105
109
106
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 " ));
111
112
}
112
113
113
114
std::unique_ptr<boost::asio::io_service> io_service_;
114
115
std::unique_ptr<tcp::resolver> resolver_;
115
116
std::unique_ptr<http::connection> connection_;
116
117
std::unique_ptr<tcp::socket> socket_;
117
118
119
+ boost::asio::streambuf request_;
120
+ boost::asio::streambuf response_;
121
+
118
122
};
119
123
120
124
int
0 commit comments