67
67
++connect_handler_called;
68
68
TEST_CHECK(c.socket().is_open());
69
std::cerr << "connected to: " << c.socket().remote_endpoint() << std::endl;
70
TEST_CHECK(c.socket().remote_endpoint().address() == address::from_string("127.0.0.1"));
70
std::cerr << "connected to: " << c.socket().remote_endpoint(ec) << std::endl;
71
TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec));
73
74
void http_handler(error_code const& ec, http_parser const& parser
105
106
std::cerr << " ===== TESTING: " << url << " =====" << std::endl;
108
std::cerr << " expecting: size: " << size
109
<< " status: " << status
110
<< " connected: " << connected
111
<< " error: " << (ec?ec->message():"no error") << std::endl;
107
113
boost::shared_ptr<http_connection> h(new http_connection(ios, cq
108
114
, &::http_handler, true, &::http_connect_handler));
109
115
h->get(url, seconds(1), 0, &ps);
113
120
std::cerr << "connect_handler_called: " << connect_handler_called << std::endl;
114
121
std::cerr << "handler_called: " << handler_called << std::endl;
137
144
// this requires the hosts file to be modified
138
145
// run_test(protocol + "://test.dns.ts:8001/test_file", 3216, 200, 1, error_code(), ps);
140
run_test(protocol + "://127.0.0.1:8001/relative/redirect", 3216, 200, 2, error_code(), ps);
141
run_test(protocol + "://127.0.0.1:8001/redirect", 3216, 200, 2, error_code(), ps);
142
run_test(protocol + "://127.0.0.1:8001/infinite_redirect", 0, 301, 6, error_code(), ps);
143
run_test(protocol + "://127.0.0.1:8001/test_file", 3216, 200, 1, error_code(), ps);
144
run_test(protocol + "://127.0.0.1:8001/test_file.gz", 3216, 200, 1, error_code(), ps);
145
run_test(protocol + "://127.0.0.1:8001/non-existing-file", -1, 404, 1, err(), ps);
148
snprintf(url, sizeof(url), "%s://127.0.0.1:%d/", protocol.c_str(), port);
149
std::string url_base(url);
151
run_test(url_base + "relative/redirect", 3216, 200, 2, error_code(), ps);
152
run_test(url_base + "redirect", 3216, 200, 2, error_code(), ps);
153
run_test(url_base + "infinite_redirect", 0, 301, 6, error_code(), ps);
154
run_test(url_base + "test_file", 3216, 200, 1, error_code(), ps);
155
run_test(url_base + "test_file.gz", 3216, 200, 1, error_code(), ps);
156
run_test(url_base + "non-existing-file", -1, 404, 1, err(), ps);
146
157
// if we're going through an http proxy, we won't get the same error as if the hostname
147
158
// resolution failed
148
159
if ((ps.type == proxy_settings::http || ps.type == proxy_settings::http_pw) && protocol != "https")
170
181
ps.username = "testuser";
171
182
ps.password = "testpass";
173
start_web_server(8001);
184
int port = start_web_server();
174
185
for (int i = 0; i < 5; ++i)
176
187
ps.type = (proxy_settings::proxy_type)i;
177
run_suite("http", ps);
188
run_suite("http", ps, port);
179
stop_web_server(8001);
181
192
#ifdef TORRENT_USE_OPENSSL
182
start_web_server(8001, true);
193
port = start_web_server(true);
183
194
for (int i = 0; i < 5; ++i)
185
196
ps.type = (proxy_settings::proxy_type)i;
186
run_suite("https", ps);
197
run_suite("https", ps, port);
188
stop_web_server(8001);
191
202
std::remove("test_file");