Repository navigation
Expand file tree
/
Copy pathclient_get_test.cpp
More file actions
84 lines (75 loc) · 2.77 KB
/
Copy pathclient_get_test.cpp
File metadata and controls
84 lines (75 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2010 Dean Michael Berris.
// Copyright 2017 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <gtest/gtest.h>
#include <boost/network/protocol/http/client.hpp>
#include "client_types.hpp"
namespace net = boost::network;
namespace http = boost::network::http;
TYPED_TEST_CASE(HTTPClientTest, ClientTypes);
TYPED_TEST(HTTPClientTest, GetTest) {
using client = TypeParam;
typename client::request request("http://cpp-netlib.org/");
typename client::options options;
options.remove_chunk_markers(true);
client client_(options);
typename client::response response;
ASSERT_NO_THROW(response = client_.get(request));
try {
auto data = body(response);
std::cout << data;
} catch (...) {
FAIL() << "Caught exception while retrieving body from GET request";
}
EXPECT_EQ("HTTP/1.", response.version().substr(0, 7));
EXPECT_TRUE(response.status() == 200u ||
(response.status() >= 300 && response.status() < 400));
}
#ifdef BOOST_NETWORK_ENABLE_HTTPS
TYPED_TEST(HTTPClientTest, GetHTTPSTest) {
using client = TypeParam;
typename client::request request("https://www.github.com/");
typename client::options options;
options.remove_chunk_markers(true);
client client_(options);
typename client::response response = client_.get(request);
EXPECT_TRUE(response.status() == 200 ||
(response.status() >= 300 && response.status() < 400));
try {
auto data = body(response);
std::cout << data;
} catch (...) {
FAIL() << "Caught exception while retrieving body from GET request";
}
}
#endif
TYPED_TEST(HTTPClientTest, TemporaryClientObjectTest) {
using client = TypeParam;
typename client::request request("http://cpp-netlib.org/");
typename client::response response;
typename client::options options;
options.remove_chunk_markers(true);
ASSERT_NO_THROW(response = client(options).get(request));
auto range = headers(response);
ASSERT_TRUE(!boost::empty(range));
try {
auto data = body(response);
std::cout << data;
} catch (...) {
FAIL() << "Caught exception while retrieving body from GET request";
}
EXPECT_EQ("HTTP/1.", response.version().substr(0, 7));
EXPECT_TRUE(response.status() == 200u ||
(response.status() >= 300 && response.status() < 400));
}
TYPED_TEST(HTTPClientTest, PropagatesResolutionErrorsTest) {
using client = TypeParam;
typename client::request request("http://malformed.google.comq");
typename client::response response;
typename client::options options;
typename client::string_type response_body;
ASSERT_NO_THROW(response = client(options).get(request));
EXPECT_THROW(response_body = body(response), std::exception);
}