Skip to content

Commit 8bcce7a

Browse files
committed
First commit of network::http::v2::client.
1 parent 297a773 commit 8bcce7a

File tree

8 files changed

+305
-0
lines changed

8 files changed

+305
-0
lines changed

http/src/network/http/v2/client.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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_CLIENT_INC__
7+
#define __NETWORK_HTTP_V2_CLIENT_INC__
8+
9+
#include <cstdint>
10+
11+
namespace network {
12+
namespace http {
13+
namespace v2 {
14+
class client {
15+
16+
public:
17+
18+
client() { }
19+
client(client const &) = delete;
20+
client(client &&) = delete;
21+
22+
};
23+
} // namespace v2
24+
} // namespace http
25+
} // namespace network
26+
27+
#endif // __NETWORK_HTTP_V2_CLIENT_INC__
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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_CLIENT_OPTIONS_INC__
7+
#define __NETWORK_HTTP_V2_CLIENT_OPTIONS_INC__
8+
9+
#include <cstdint>
10+
#include <algorithm>
11+
12+
namespace network {
13+
namespace http {
14+
namespace v2 {
15+
class client_options {
16+
17+
public:
18+
19+
// default timeout is 30 seconds
20+
constexpr client_options()
21+
: follow_redirects_(false)
22+
, cache_resolved_(false)
23+
, use_proxy_(false)
24+
, timeout_(30000) { }
25+
26+
client_options(client_options const &) = default;
27+
client_options(client_options &&) = default;
28+
29+
void swap(client_options &other) noexcept {
30+
std::swap(follow_redirects_, other.follow_redirects_);
31+
std::swap(cache_resolved_, other.cache_resolved_);
32+
std::swap(use_proxy_, other.use_proxy_);
33+
std::swap(timeout_, other.timeout_);
34+
}
35+
36+
client_options &follow_redirects(bool follow_redirects) noexcept {
37+
follow_redirects_ = follow_redirects;
38+
return *this;
39+
}
40+
41+
constexpr bool follow_redirects() const noexcept {
42+
return follow_redirects_;
43+
}
44+
45+
client_options &cache_resolved(bool cache_resolved) noexcept {
46+
cache_resolved_ = cache_resolved;
47+
return *this;
48+
}
49+
50+
constexpr bool cache_resolved() const noexcept {
51+
return cache_resolved_;
52+
}
53+
54+
client_options &use_proxy(bool use_proxy) noexcept {
55+
use_proxy_ = use_proxy;
56+
return *this;
57+
}
58+
59+
constexpr bool use_proxy() const noexcept {
60+
return use_proxy_;
61+
}
62+
63+
client_options &timeout(std::uint64_t timeout) noexcept {
64+
timeout_ = timeout;
65+
return *this;
66+
}
67+
68+
constexpr std::uint64_t timeout() const noexcept {
69+
return timeout_;
70+
}
71+
72+
private:
73+
74+
bool follow_redirects_;
75+
bool cache_resolved_;
76+
bool use_proxy_;
77+
std::uint64_t timeout_;
78+
79+
};
80+
} // namespace v2
81+
} // namespace http
82+
} // namespace network
83+
84+
#endif // __NETWORK_HTTP_V2_CLIENT_OPTIONS_INC__

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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_REQUEST_INC__
7+
#define __NETWORK_HTTP_V2_REQUEST_INC__
8+
9+
#include <cstdint>
10+
11+
namespace network {
12+
namespace http {
13+
namespace v2 {
14+
class request {
15+
16+
public:
17+
18+
request() { }
19+
20+
};
21+
} // namespace v2
22+
} // namespace http
23+
} // namespace network
24+
25+
#endif // __NETWORK_HTTP_V2_REQUEST_INC__
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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_REQUEST_OPTIONS_INC__
7+
#define __NETWORK_HTTP_V2_REQUEST_OPTIONS_INC__
8+
9+
#include <cstdint>
10+
#include <algorithm>
11+
12+
namespace network {
13+
namespace http {
14+
namespace v2 {
15+
class request_options {
16+
17+
public:
18+
19+
// default timeout is 30 seconds
20+
constexpr request_options()
21+
: resolve_timeout_(30000)
22+
, read_timeout_(30000)
23+
, total_timeout_(30000) { }
24+
25+
request_options(request_options const &) = default;
26+
request_options(request_options &&) = default;
27+
28+
void swap(request_options &other) noexcept {
29+
std::swap(resolve_timeout_, other.resolve_timeout_);
30+
std::swap(read_timeout_, other.read_timeout_);
31+
std::swap(total_timeout_, other.total_timeout_);
32+
}
33+
34+
request_options &resolve_timeout(std::uint64_t resolve_timeout) noexcept {
35+
resolve_timeout_ = resolve_timeout;
36+
return *this;
37+
}
38+
39+
constexpr std::uint64_t resolve_timeout() const noexcept {
40+
return resolve_timeout_;
41+
}
42+
43+
request_options &read_timeout(std::uint64_t read_timeout) noexcept {
44+
read_timeout_ = read_timeout;
45+
return *this;
46+
}
47+
48+
constexpr std::uint64_t read_timeout() const noexcept {
49+
return read_timeout_;
50+
}
51+
52+
request_options &total_timeout(std::uint64_t total_timeout) noexcept {
53+
total_timeout_ = total_timeout;
54+
return *this;
55+
}
56+
57+
constexpr std::uint64_t total_timeout() const noexcept {
58+
return total_timeout_;
59+
}
60+
61+
private:
62+
63+
std::uint64_t resolve_timeout_;
64+
std::uint64_t read_timeout_;
65+
std::uint64_t total_timeout_;
66+
67+
};
68+
} // namespace v2
69+
} // namespace http
70+
} // namespace network
71+
72+
#endif // __NETWORK_HTTP_V2_REQUEST_OPTIONS_INC__

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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_RESPONSE_INC__
7+
#define __NETWORK_HTTP_V2_RESPONSE_INC__
8+
9+
#include <network/uri.hpp>
10+
11+
namespace network {
12+
namespace http {
13+
namespace v2 {
14+
class response {
15+
16+
public:
17+
18+
response() { }
19+
20+
};
21+
} // namespace v2
22+
} // namespace http
23+
} // namespace network
24+
25+
#endif // __NETWORK_HTTP_V2_RESPONSE_INC__

http/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ include_directories(
1212
${GTEST_INCLUDE_DIRS}
1313
${CPP-NETLIB_SOURCE_DIR})
1414

15+
add_subdirectory(client/v2)
16+
1517
if (OPENSSL_FOUND)
1618
include_directories( ${OPENSSL_INCLUDE_DIR} )
1719
add_definitions(-DNETWORK_ENABLE_HTTPS)

http/test/client/v2/CMakeLists.txt

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+
set(CPP-NETLIB_CLIENT_TESTS
7+
client_options_test
8+
)
9+
10+
foreach(test ${CPP-NETLIB_CLIENT_TESTS})
11+
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
12+
set_source_files_properties(${test}.cpp
13+
PROPERTIES COMPILE_FLAGS "-Wall")
14+
endif()
15+
16+
add_executable(cpp-netlib-http-v2-${test} ${test}.cpp)
17+
target_link_libraries(cpp-netlib-http-v2-${test}
18+
${Boost_LIBRARIES}
19+
${GTEST_BOTH_LIBRARIES}
20+
${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES}
21+
${CMAKE_THREAD_LIBS_INIT}
22+
)
23+
set_target_properties(cpp-netlib-http-v2-${test}
24+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
25+
add_test(cpp-netlib-http-v2-${test}
26+
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-v2-${test})
27+
28+
endforeach(test)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/client_options.hpp>
8+
9+
TEST(client_options_test, default_options_follow_redirects) {
10+
network::http::v2::client_options opts;
11+
ASSERT_FALSE(opts.follow_redirects());
12+
}
13+
14+
TEST(client_options_test, default_options_cache_resolved) {
15+
network::http::v2::client_options opts;
16+
ASSERT_FALSE(opts.cache_resolved());
17+
}
18+
19+
TEST(client_options_test, default_options_use_proxy) {
20+
network::http::v2::client_options opts;
21+
ASSERT_FALSE(opts.use_proxy());
22+
}
23+
24+
TEST(client_options_test, set_option_follow_redirects) {
25+
network::http::v2::client_options opts;
26+
opts.follow_redirects(true);
27+
ASSERT_TRUE(opts.follow_redirects());
28+
}
29+
30+
TEST(client_options_test, set_option_cache_resolved) {
31+
network::http::v2::client_options opts;
32+
opts.cache_resolved(true);
33+
ASSERT_TRUE(opts.cache_resolved());
34+
}
35+
36+
TEST(client_options_test, set_option_use_proxy) {
37+
network::http::v2::client_options opts;
38+
opts.use_proxy(true);
39+
ASSERT_TRUE(opts.use_proxy());
40+
}
41+
42+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy