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

Commit42ab79d

Browse files
committed
Simplified the HTTP client, request and response classes.
1 parente2da305 commit42ab79d

File tree

4 files changed

+55
-153
lines changed

4 files changed

+55
-153
lines changed

‎http/src/http/v2/client/client.cpp

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

66
#include<boost/asio/strand.hpp>
7+
#include<boost/asio/deadline_timer.hpp>
78
#include<boost/algorithm/string/trim.hpp>
89
#include<boost/algorithm/string/predicate.hpp>
910
#include<boost/range/algorithm/find_first_of.hpp>
@@ -143,8 +144,6 @@ namespace network {
143144
std::shared_ptr<request_context> context) {
144145
std::future<response> res = context->response_promise_.get_future();
145146

146-
// TODO see linearize.hpp
147-
148147
// If there is no user-agent, provide one as a default.
149148
auto user_agent = context->request_.header("User-Agent");
150149
if (!user_agent) {
@@ -330,11 +329,13 @@ namespace network {
330329

331330
// if options_.follow_redirects()
332331
// and if status in range 300 - 307
333-
// then take the request and reset the URL
332+
// then take the request and reset the URL from the 'Location' header
333+
// restart connection
334+
// Not that the 'Location' header can be a *relative* URI
334335

335336
std::shared_ptr<response>res(new response{});
336337
res->set_version(version);
337-
res->set_status(network::http::v2::status::code(status));
338+
res->set_status(network::http::status::code(status));
338339
res->set_status_message(boost::trim_copy(message));
339340

340341
// Read the response headers.

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

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include<string>
2121
#include<vector>
2222
#include<chrono>
23-
#include<boost/asio/io_service.hpp>
24-
#include<boost/asio/deadline_timer.hpp>
2523
#include<boost/optional.hpp>
2624
#include<network/config.hpp>
2725
#include<network/version.hpp>
@@ -49,8 +47,7 @@ class client_options {
4947
* \brief Constructor.
5048
*/
5149
client_options()
52-
: io_service_(boost::none)
53-
, follow_redirects_(false)
50+
: follow_redirects_(false)
5451
, cache_resolved_(false)
5552
, use_proxy_(false)
5653
, always_verify_peer_(false)
@@ -60,30 +57,12 @@ class client_options {
6057
/**
6158
* \brief Copy constructor.
6259
*/
63-
client_options(const client_options &other)
64-
: io_service_(other.io_service_)
65-
, follow_redirects_(other.follow_redirects_)
66-
, cache_resolved_(other.cache_resolved_)
67-
, use_proxy_(other.use_proxy_)
68-
, always_verify_peer_(other.always_verify_peer_)
69-
, user_agent_(other.user_agent_)
70-
, timeout_(other.timeout_)
71-
, openssl_certificate_paths_(other.openssl_certificate_paths_)
72-
, openssl_verify_paths_(other.openssl_verify_paths_) { }
60+
client_options(const client_options &other) =default;
7361

7462
/**
7563
* \brief Move constructor.
7664
*/
77-
client_options(client_options &&other)
78-
: io_service_(std::move(other.io_service_))
79-
, follow_redirects_(std::move(other.follow_redirects_))
80-
, cache_resolved_(std::move(other.cache_resolved_))
81-
, use_proxy_(std::move(other.use_proxy_))
82-
, always_verify_peer_(std::move(other.always_verify_peer_))
83-
, user_agent_(std::move(other.user_agent_))
84-
, timeout_(std::move(other.timeout_))
85-
, openssl_certificate_paths_(std::move(other.openssl_certificate_paths_))
86-
, openssl_verify_paths_(std::move(other.openssl_verify_paths_)) { }
65+
client_options(client_options &&other) =default;
8766

8867
/**
8968
* \brief Assignment operator.
@@ -96,16 +75,13 @@ class client_options {
9675
/**
9776
* \brief Destructor.
9877
*/
99-
~client_options() {
100-
101-
}
78+
~client_options() =default;
10279

10380
/**
10481
* \brief Swap.
10582
*/
10683
voidswap(client_options &other)noexcept {
10784
using std::swap;
108-
std::swap(io_service_, other.io_service_);
10985
swap(follow_redirects_, other.follow_redirects_);
11086
swap(cache_resolved_, other.cache_resolved_);
11187
swap(use_proxy_, other.use_proxy_);
@@ -116,23 +92,6 @@ class client_options {
11692
swap(openssl_verify_paths_, other.openssl_verify_paths_);
11793
}
11894

119-
/**
120-
* \brief Overrides the client's I/O service.
121-
* \param io_service The new io_service object to use.
122-
*/
123-
client_options &io_service(boost::asio::io_service &io_service) {
124-
io_service_ = io_service;
125-
return *this;
126-
}
127-
128-
/**
129-
* \brief Gets the overridden I/O service.
130-
* \returns An optional io_service object.
131-
*/
132-
boost::optional<boost::asio::io_service &>io_service()const {
133-
return io_service_;
134-
}
135-
13695
/**
13796
* \brief Tells the client to follow redirects.
13897
* \param follow_redirects If \c true, then the client must
@@ -284,7 +243,6 @@ class client_options {
284243

285244
private:
286245

287-
boost::optional<boost::asio::io_service &> io_service_;
288246
bool follow_redirects_;
289247
bool cache_resolved_;
290248
bool use_proxy_;

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

Lines changed: 43 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,12 @@ class request_options {
6262
/**
6363
* \brief Copy constructor.
6464
*/
65-
request_options(request_optionsconst &other)
66-
: resolve_timeout_(other.resolve_timeout_)
67-
, read_timeout_(other.read_timeout_)
68-
, total_timeout_(other.total_timeout_)
69-
, max_redirects_(other.max_redirects_) { }
65+
request_options(request_optionsconst &other) =default;
7066

7167
/**
7268
* \brief Move constructor.
7369
*/
74-
request_options(request_options &&other)
75-
: resolve_timeout_(std::move(other.resolve_timeout_))
76-
, read_timeout_(std::move(other.read_timeout_))
77-
, total_timeout_(std::move(other.total_timeout_))
78-
, max_redirects_(std::move(other.max_redirects_)) { }
70+
request_options(request_options &&other) =default;
7971

8072
/**
8173
* \brief Assignment operator.
@@ -88,9 +80,7 @@ class request_options {
8880
/**
8981
* \brief Destructor.
9082
*/
91-
~request_options() {
92-
93-
}
83+
~request_options() =default;
9484

9585
/**
9686
* \brief
@@ -312,14 +302,49 @@ class request {
312302
/**
313303
* \brief Constructor.
314304
*/
315-
request()
316-
: byte_source_(nullptr) { }
305+
request() =default;
317306

318307
/**
319308
* \brief Constructor.
320309
*/
321-
explicitrequest(uri url)
322-
: url_(url) {
310+
explicitrequest(uri url) {
311+
this->url(url);
312+
}
313+
314+
/**
315+
* \brief Copy constructor.
316+
*/
317+
request(const request &other) =default;
318+
319+
/**
320+
* \brief Move constructor.
321+
*/
322+
request(request &&other)noexcept =default;
323+
324+
/**
325+
* \brief Destructor.
326+
*/
327+
~request() =default;
328+
329+
/**
330+
* \brief Swaps one request object with another.
331+
* \param other The other request object.
332+
*/
333+
voidswap(request &other)noexcept {
334+
using std::swap;
335+
swap(url_, other.url_);
336+
swap(method_, other.method_);
337+
swap(path_, other.path_);
338+
swap(version_, other.version_);
339+
swap(headers_, other.headers_);
340+
swap(byte_source_, other.byte_source_);
341+
}
342+
343+
/**
344+
* \brief
345+
* \returns
346+
*/
347+
request &url(const uri &url) {
323348
if (auto scheme = url.scheme()) {
324349
if ((!boost::equal(*scheme,boost::as_literal("http"))) &&
325350
(!boost::equal(*scheme,boost::as_literal("https")))) {
@@ -356,65 +381,6 @@ class request {
356381
else {
357382
throwinvalid_url();
358383
}
359-
}
360-
361-
/**
362-
* \brief Copy constructor.
363-
*/
364-
request(const request &other)
365-
: url_(other.url_)
366-
, method_(other.method_)
367-
, path_(other.path_)
368-
, version_(other.version_)
369-
, headers_(other.headers_)
370-
, byte_source_(other.byte_source_) { }
371-
372-
/**
373-
* \brief Move constructor.
374-
*/
375-
request(request &&other)noexcept
376-
: url_(std::move(other.url_))
377-
, method_(std::move(other.method_))
378-
, path_(std::move(other.path_))
379-
, version_(std::move(other.version_))
380-
, headers_(std::move(other.headers_))
381-
, byte_source_(std::move(other.byte_source_)) { }
382-
383-
/**
384-
* \brief Assignment operator.
385-
*/
386-
request &operator = (request other) {
387-
other.swap(*this);
388-
return *this;
389-
}
390-
391-
/**
392-
* \brief Destructor.
393-
*/
394-
~request() {
395-
396-
}
397-
398-
/**
399-
* \brief Swaps one request object with another.
400-
* \param other The other request object.
401-
*/
402-
voidswap(request &other)noexcept {
403-
using std::swap;
404-
swap(url_, other.url_);
405-
swap(method_, other.method_);
406-
swap(path_, other.path_);
407-
swap(version_, other.version_);
408-
swap(headers_, other.headers_);
409-
swap(byte_source_, other.byte_source_);
410-
}
411-
412-
/**
413-
* \brief
414-
* \returns
415-
*/
416-
request &url(const uri &url) {
417-
// throw invalid_url
418384
url_ = url;
419385
return *this;
420386
}
@@ -516,7 +482,7 @@ class request {
516482
* Duplicates are allowed.
517483
*/
518484
request &append_header(string_type name, string_type value) {
519-
headers_.emplace_back(std::make_pair(name, value));
485+
headers_.emplace_back(name, value);
520486
return *this;
521487
}
522488

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,42 +63,19 @@ class response {
6363
/**
6464
* \brief Constructor.
6565
*/
66-
response(){ }
66+
response()=default;
6767

6868
/**
6969
* \brief Copy constructor.
7070
* \param other The other response object.
7171
*/
72-
response(const response &other)
73-
: version_(other.version_)
74-
, status_(other.status_)
75-
, status_message_(other.status_message_)
76-
, headers_(other.headers_)
77-
, body_(other.body_) {
78-
79-
}
72+
response(const response &other) =default;
8073

8174
/**
8275
* \brief Move constructor.
8376
* \param other The other response object.
8477
*/
85-
response(response &&other)noexcept
86-
: version_(std::move(other.version_))
87-
, status_(std::move(other.status_))
88-
, status_message_(std::move(other.status_message_))
89-
, headers_(std::move(other.headers_))
90-
, body_(std::move(other.body_)) {
91-
92-
}
93-
94-
/**
95-
* \brief Assignment operator.
96-
* \param other The other response object.
97-
*/
98-
response &operator= (response other) {
99-
other.swap(*this);
100-
return *this;
101-
}
78+
response(response &&other)noexcept =default;
10279

10380
/**
10481
* \brief Swap function.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp