Skip to content

Commit fb7eecf

Browse files
committed
Updated first set of HTTP client tests.
1 parent 8bcce7a commit fb7eecf

File tree

11 files changed

+171
-3
lines changed

11 files changed

+171
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (C) 2013 by Glyn Matthews
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#ifndef __NETWORK_HTTP_V2_BYTE_SOURCE_INC__
7+
#define __NETWORK_HTTP_V2_BYTE_SOURCE_INC__
8+
9+
#include <cstdint>
10+
#include <memory>
11+
12+
namespace network {
13+
namespace http {
14+
namespace v2 {
15+
class byte_source {
16+
17+
public:
18+
19+
virtual ~byte_source() {}
20+
21+
virtual std::size_t read(std::string &source, std::size_t length) = 0;
22+
23+
};
24+
25+
class string_byte_source : public byte_source {
26+
27+
explicit string_byte_source(std::string source);
28+
29+
virtual ~string_byte_source() {}
30+
31+
virtual std::size_t read(std::string &source, std::size_t length);
32+
33+
std::string source_;
34+
35+
};
36+
} // namespace v2
37+
} // namespace http
38+
} // namespace network
39+
40+
#endif // __NETWORK_HTTP_V2_BYTE_SOURCE_INC__

http/src/network/http/v2/client_options.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ namespace v2 {
2626
client_options(client_options const &) = default;
2727
client_options(client_options &&) = default;
2828

29+
client_options &operator = (client_options other) {
30+
other.swap(*this);
31+
return *this;
32+
}
33+
2934
void swap(client_options &other) noexcept {
3035
std::swap(follow_redirects_, other.follow_redirects_);
3136
std::swap(cache_resolved_, other.cache_resolved_);

http/src/network/http/v2/request.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#define __NETWORK_HTTP_V2_REQUEST_INC__
88

99
#include <cstdint>
10+
#include <memory>
11+
#include <network/uri.hpp>
12+
#include <network/http/v2/byte_source.hpp>
1013

1114
namespace network {
1215
namespace http {
@@ -15,7 +18,26 @@ namespace v2 {
1518

1619
public:
1720

18-
request() { }
21+
request(uri locator, std::shared_ptr<byte_source> = nullptr)
22+
: locator_(locator) { }
23+
24+
// destination
25+
// source
26+
// add_header
27+
// remove_header
28+
// clear_headers
29+
// set_body
30+
// append_body
31+
// get_body
32+
33+
// method
34+
// status
35+
// status_message
36+
// uri
37+
// version
38+
39+
uri locator_;
40+
std::shared_ptr<byte_source> source_;
1941

2042
};
2143
} // namespace v2

http/src/network/http/v2/request_options.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ namespace v2 {
2525
request_options(request_options const &) = default;
2626
request_options(request_options &&) = default;
2727

28+
request_options &operator = (request_options other) {
29+
other.swap(*this);
30+
return *this;
31+
}
32+
2833
void swap(request_options &other) noexcept {
2934
std::swap(resolve_timeout_, other.resolve_timeout_);
3035
std::swap(read_timeout_, other.read_timeout_);

http/src/network/http/v2/response.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#ifndef __NETWORK_HTTP_V2_RESPONSE_INC__
77
#define __NETWORK_HTTP_V2_RESPONSE_INC__
88

9+
#include <cstdint>
10+
#include <map>
11+
#include <string>
12+
#include <future>
913
#include <network/uri.hpp>
1014

1115
namespace network {
@@ -15,8 +19,33 @@ namespace v2 {
1519

1620
public:
1721

22+
typedef std::multimap<std::string, std::string> headers_type;
23+
typedef headers_type::const_iterator headers_iterator;
24+
typedef headers_type::const_iterator const_headers_iterator;
25+
1826
response() { }
1927

28+
std::uint16_t status() const;
29+
std::string status_message() const;
30+
const_headers_iterator headers_begin() const;
31+
const_headers_iterator end_begin() const;
32+
std::pair<headers_iterator, headers_iterator> headers() const;
33+
std::future<std::string> read_body(std::size_t length) const;
34+
35+
// destination
36+
// source
37+
// add_header
38+
// remove_header
39+
// set_body
40+
// append_body
41+
// get_body
42+
43+
private:
44+
45+
struct impl;
46+
impl *pimpl_;
47+
48+
2049
};
2150
} // namespace v2
2251
} // namespace http

http/test/client/v2/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
# http://www.boost.org/LICENSE_1_0.txt)
55

66
set(CPP-NETLIB_CLIENT_TESTS
7+
response_test
78
client_options_test
9+
request_options_test
10+
byte_source_test
11+
request_test
812
)
913

1014
foreach(test ${CPP-NETLIB_CLIENT_TESTS})
@@ -15,6 +19,7 @@ foreach(test ${CPP-NETLIB_CLIENT_TESTS})
1519

1620
add_executable(cpp-netlib-http-v2-${test} ${test}.cpp)
1721
target_link_libraries(cpp-netlib-http-v2-${test}
22+
cppnetlib-uri
1823
${Boost_LIBRARIES}
1924
${GTEST_BOTH_LIBRARIES}
2025
${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (C) 2013 by Glyn Matthews
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#include <gtest/gtest.h>
7+
#include <network/http/v2/byte_source.hpp>
8+
9+

http/test/client/v2/client_options_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,3 @@ TEST(client_options_test, set_option_use_proxy) {
3838
opts.use_proxy(true);
3939
ASSERT_TRUE(opts.use_proxy());
4040
}
41-
42-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2013 by Glyn Matthews
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#include <gtest/gtest.h>
7+
#include <network/http/v2/request_options.hpp>
8+
9+
TEST(request_options_test, default_options_resolve_timeout) {
10+
network::http::v2::request_options opts;
11+
ASSERT_EQ(30000, opts.resolve_timeout());
12+
}
13+
14+
TEST(request_options_test, default_options_read_timeout) {
15+
network::http::v2::request_options opts;
16+
ASSERT_EQ(30000, opts.read_timeout());
17+
}
18+
19+
TEST(request_options_test, default_options_total_timeout) {
20+
network::http::v2::request_options opts;
21+
ASSERT_EQ(30000, opts.total_timeout());
22+
}
23+
24+
TEST(request_options_test, set_resolve_timeout) {
25+
network::http::v2::request_options opts;
26+
opts.resolve_timeout(10000);
27+
ASSERT_EQ(10000, opts.resolve_timeout());
28+
}

http/test/client/v2/request_test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2013 by Glyn Matthews
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#include <gtest/gtest.h>
7+
#include <network/http/v2/request.hpp>
8+
9+
TEST(request_test, request_constructor_url) {
10+
ASSERT_NO_THROW(network::http::v2::request(network::uri("http://www.example.com/")));
11+
}
12+
13+
TEST(request_test, request_constructor_https_url) {
14+
ASSERT_NO_THROW(network::http::v2::request(network::uri("https://www.example.com/")));
15+
}
16+
17+
//TEST(request_test, request_constructor_invalid_url) {
18+
// ASSERT_THROW(network::http::v2::invalid_scheme,
19+
// network::http::v2::request(network::uri("mailto:john.doe@example.com")));
20+
//}

0 commit comments

Comments
 (0)