Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebd7567

Browse files
committed
Updated tests for the response parser, added cancellation member function to the connection delegate.
1 parent8976b43 commitebd7567

File tree

6 files changed

+173
-44
lines changed

6 files changed

+173
-44
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace network {
3939
virtualvoidasync_read_some(const boost::asio::mutable_buffers_1 &read_buffer,
4040
read_callback callback) = 0;
4141

42+
virtualvoidcancel() = 0;
43+
4244
};
4345
}// namespace v2
4446
}// namespace http

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ namespace network {
4646
socket_->async_read_some(read_buffer, callback);
4747
}
4848

49+
virtualvoidcancel() {
50+
socket_->cancel();
51+
}
52+
4953
private:
5054

5155
boost::asio::io_service &io_service_;
5256
std::unique_ptr<boost::asio::ip::tcp::socket> socket_;
53-
std::promise<std::pair<boost::system::error_code, std::size_t>> read_promise_;
5457

5558
};
5659
}// namespace v2

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ namespace network {
3636

3737
}
3838

39-
virtualvoidconnect(boost::asio::ip::tcp::endpoint &endpoint,
40-
const std::string &host,
41-
std::function<void (const boost::system::error_code &)> handler) {
39+
virtualvoidasync_connect(boost::asio::ip::tcp::endpoint &endpoint,
40+
const std::string &host,
41+
connect_callback callback) {
4242
context_.reset(newboost::asio::ssl::context(boost::asio::ssl::context::sslv23));
4343
std::vector<std::string>const& certificate_paths =
4444
options_.openssl_certificate_paths();
@@ -64,23 +64,23 @@ namespace network {
6464

6565
usingnamespacestd::placeholders;
6666
socket_->lowest_layer()
67-
.async_connect(endpoint,
68-
std::bind(&ssl_connection_delegate::handle_connected,
69-
ssl_connection_delegate::shared_from_this(),
70-
_1,
71-
handler));
72-
}
67+
.async_connect(endpoint, callback);
68+
}
7369

74-
virtualvoidwrite(boost::asio::streambuf &command_streambuf,
75-
std::function<void (const boost::system::error_code &,size_t)> handler) {
76-
boost::asio::async_write(*socket_, command_streambuf,handler);
70+
virtualvoidasync_write(boost::asio::streambuf &command_streambuf,
71+
write_callback callback) {
72+
boost::asio::async_write(*socket_, command_streambuf,callback);
7773
}
7874

79-
virtualvoidread_some(const boost::asio::mutable_buffers_1 &read_buffer,
80-
std::function<void (const boost::system::error_code &,size_t)> handler) {
81-
socket_->async_read_some(read_buffer,handler);
75+
virtualvoidasync_read_some(const boost::asio::mutable_buffers_1 &read_buffer,
76+
read_callback callback) {
77+
socket_->async_read_some(read_buffer,callback);
8278
}
8379

80+
virtualvoidcancel() {
81+
socket_->cancel();
82+
}
83+
8484
private:
8585

8686
boost::asio::io_service &io_service_;
@@ -89,9 +89,6 @@ namespace network {
8989
std::unique_ptr<
9090
boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> socket_;
9191

92-
voidhandle_connected(boost::system::error_codeconst& ec,
93-
std::function<void(const boost::system::error_code &)> handler);
94-
9592
};
9693
}// namespace v2
9794
}// namespace http

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include<thread>
88
#include<igloo/igloo_alt.h>
99
#include<boost/asio.hpp>
10-
#include"network/http/v2/client/connection/async_resolver_delegate.hpp"
1110
#include"network/http/v2/client/connection/normal_connection_delegate.hpp"
1211
#include"network/http/v2/client/request.hpp"
1312

‎http/test/v2/features/client/ssl_connection_test.cpp‎

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,142 @@
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

6-
#include<igloo/igloo.h>
6+
#include<memory>
7+
#include<thread>
8+
#include<igloo/igloo_alt.h>
79
#include<boost/asio.hpp>
810
#include"network/http/v2/client/connection/ssl_connection_delegate.hpp"
11+
#include"network/http/v2/client/request.hpp"
912

1013
usingnamespaceigloo;
1114
using boost::asio::ip::tcp;
1215
namespacehttp= network::http::v2;
1316

17+
Describe(https_connection) {
18+
19+
voidSetUp() {
20+
io_service_.reset(new boost::asio::io_service);
21+
resolver_.reset(newtcp::resolver(*io_service_));
22+
options_.reset(new http::client_options);
23+
connection_.reset(newhttp::ssl_connection_delegate(*io_service_, *options_));
24+
socket_.reset(newtcp::socket(*io_service_));
25+
}
26+
27+
voidTearDown() {
28+
socket_->close();
29+
}
30+
31+
It(connects_to_localhost) {
32+
// Resolve the host.
33+
boost::system::error_code ec;
34+
tcp::resolver::queryquery("127.0.0.1","80");
35+
auto it = resolver_->resolve(query, ec);
36+
Assert::That(ec,Equals(boost::system::error_code()));
37+
38+
// Make sure that the connection is successful.
39+
tcp::endpointendpoint(it->endpoint());
40+
connection_->async_connect(endpoint,"127.0.0.1",
41+
[&ec] (const boost::system::error_code &ec_) {
42+
ec = ec_;
43+
});
44+
io_service_->run_one();
45+
Assert::That(ec,Equals(boost::system::error_code()));
46+
}
47+
48+
/*
49+
It(writes_to_localhost) {
50+
// Resolve the host.
51+
boost::system::error_code ec;
52+
tcp::resolver::query query("127.0.0.1", "80");
53+
auto it = resolver_->resolve(query, ec);
54+
Assert::That(ec, Equals(boost::system::error_code()));
55+
56+
// Make sure that the connection is successful.
57+
tcp::endpoint endpoint(it->endpoint());
58+
connection_->async_connect(endpoint, "127.0.0.1",
59+
[&ec] (const boost::system::error_code &ec_) {
60+
Assert::That(ec_, Equals(boost::system::error_code()));
61+
});
62+
63+
// Create an HTTPS request.
64+
http::request request{network::uri{"http://127.0.0.1/"}};
65+
request.set_method(http::method::GET);
66+
request.set_version("1.0");
67+
request.append_header("User-Agent", "ssl_connection_test");
68+
request.append_header("Connection", "close");
69+
70+
// Write the HTTP request to the socket, sending it to the server.
71+
boost::asio::streambuf request_;
72+
std::ostream request_stream(&request_);
73+
request_stream << request;
74+
std::size_t bytes_written = 0;
75+
connection_->async_write(request_,
76+
[&bytes_written] (const boost::system::error_code &ec_,
77+
std::size_t bytes_written_) {
78+
Assert::That(ec_, Equals(boost::system::error_code()));
79+
bytes_written = bytes_written_;
80+
});
81+
io_service_->run();
82+
Assert::That(bytes_written, IsGreaterThan(0));
83+
}
84+
85+
It(reads_from_localhost) {
86+
// Resolve the host.
87+
boost::system::error_code ec;
88+
tcp::resolver::query query("127.0.0.1", "80");
89+
auto it = resolver_->resolve(query, ec);
90+
Assert::That(ec, Equals(boost::system::error_code()));
91+
92+
// Make sure that the connection is successful.
93+
tcp::endpoint endpoint(it->endpoint());
94+
connection_->async_connect(endpoint, "127.0.0.1",
95+
[] (const boost::system::error_code &ec_) {
96+
Assert::That(ec_, Equals(boost::system::error_code()));
97+
});
98+
99+
// Create an HTTP request.
100+
http::request request{network::uri{"http://127.0.0.1/"}};
101+
request.set_method(http::method::GET);
102+
request.set_version("1.0");
103+
request.append_header("User-Agent", "ssl_connection_test");
104+
request.append_header("Connection", "close");
105+
106+
// Write the HTTP request to the socket, sending it to the server.
107+
boost::asio::streambuf request_;
108+
std::ostream request_stream(&request_);
109+
request_stream << request;
110+
std::size_t bytes_written = 0;
111+
connection_->async_write(request_,
112+
[&bytes_written] (const boost::system::error_code &ec_,
113+
std::size_t bytes_written_) {
114+
Assert::That(ec_, Equals(boost::system::error_code()));
115+
bytes_written = bytes_written_;
116+
});
117+
118+
// Read the HTTP response on the socket from the server.
119+
char output[8192];
120+
std::memset(output, 0, sizeof(output));
121+
std::size_t bytes_read = 0;
122+
connection_->async_read_some(boost::asio::mutable_buffers_1(output, sizeof(output)),
123+
[&bytes_read] (const boost::system::error_code &ec_,
124+
std::size_t bytes_read_) {
125+
Assert::That(ec_, Equals(boost::system::error_code()));
126+
bytes_read = bytes_read_;
127+
});
128+
129+
io_service_->run();
130+
Assert::That(bytes_read, IsGreaterThan(0));
131+
}
132+
*/
133+
134+
std::unique_ptr<boost::asio::io_service> io_service_;
135+
std::unique_ptr<tcp::resolver> resolver_;
136+
std::unique_ptr<http::client_options> options_;
137+
std::unique_ptr<http::connection_delegate> connection_;
138+
std::unique_ptr<tcp::socket> socket_;
139+
140+
};
141+
14142
int
15143
main(int argc,char *argv[]) {
16144
returnTestRunner::RunAllTests(argc,const_cast<constchar **>(argv));

‎http/test/v2/units/client/response_parser_test.cpp‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ namespace {
2121
"Connection: close\r\n"
2222
"Content-Type: text/plain\r\n"
2323
"\r\n"
24-
"Boost Software License - Version 1.0 - August 17th, 2003\r\n"
25-
"\r\n"
26-
"Permission is hereby granted, free of charge, to any person or organization\r\n"
27-
"obtaining a copy of the software and accompanying documentation covered by\r\n"
28-
"this license (the\"Software\") to use, reproduce, display, distribute,\r\n"
29-
"execute, and transmit the Software, and to prepare derivative works of the\r\n"
30-
"Software, and to permit third-parties to whom the Software is furnished to\r\n"
31-
"do so, all subject to the following:\r\n"
32-
"\r\n"
33-
"The copyright notices in the Software and this entire statement, including\r\n"
34-
"the above license grant, this restriction and the following disclaimer,\r\n"
35-
"must be included in all copies of the Software, in whole or in part, and\r\n"
36-
"all derivative works of the Software, unless such copies or derivative\r\n"
37-
"works are solely in the form of machine-executable object code generated by\r\n"
38-
"a source language processor.\r\n"
39-
"\r\n"
40-
"THE SOFTWARE IS PROVIDED\"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n"
41-
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n"
42-
"FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\r\n"
43-
"SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\r\n"
44-
"FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\r\n"
45-
"ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r\n"
46-
"DEALINGS IN THE SOFTWARE.\r\n"
24+
"Boost Software License - Version 1.0 - August 17th, 2003\n"
25+
"\n"
26+
"Permission is hereby granted, free of charge, to any person or organization\n"
27+
"obtaining a copy of the software and accompanying documentation covered by\n"
28+
"this license (the\"Software\") to use, reproduce, display, distribute,\n"
29+
"execute, and transmit the Software, and to prepare derivative works of the\n"
30+
"Software, and to permit third-parties to whom the Software is furnished to\n"
31+
"do so, all subject to the following:\n"
32+
"\n"
33+
"The copyright notices in the Software and this entire statement, including\n"
34+
"the above license grant, this restriction and the following disclaimer,\n"
35+
"must be included in all copies of the Software, in whole or in part, and\n"
36+
"all derivative works of the Software, unless such copies or derivative\n"
37+
"works are solely in the form of machine-executable object code generated by\n"
38+
"a source language processor.\n"
39+
"\n"
40+
"THE SOFTWARE IS PROVIDED\"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
41+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
42+
"FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\n"
43+
"SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\n"
44+
"FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\n"
45+
"ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n"
46+
"DEALINGS IN THE SOFTWARE.\n"
4747
;
4848

4949
inline

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp