Make request, response const
This commit is contained in:
parent
0676535caf
commit
8afd75ca47
|
@ -73,7 +73,7 @@ int main(int argc, char *argv[]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
req->on_response([&sess, req](response &res) {
|
req->on_response([&sess, req](const response &res) {
|
||||||
std::cerr << "response header was received" << std::endl;
|
std::cerr << "response header was received" << std::endl;
|
||||||
print_header(res);
|
print_header(res);
|
||||||
|
|
||||||
|
@ -87,12 +87,12 @@ int main(int argc, char *argv[]) {
|
||||||
std::cerr << "request done with error_code=" << error_code << std::endl;
|
std::cerr << "request done with error_code=" << error_code << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
req->on_push([](request &push_req) {
|
req->on_push([](const request &push_req) {
|
||||||
std::cerr << "push request was received" << std::endl;
|
std::cerr << "push request was received" << std::endl;
|
||||||
|
|
||||||
print_header(push_req);
|
print_header(push_req);
|
||||||
|
|
||||||
push_req.on_response([](response &res) {
|
push_req.on_response([](const response &res) {
|
||||||
std::cerr << "push response header was received" << std::endl;
|
std::cerr << "push response header was received" << std::endl;
|
||||||
|
|
||||||
res.on_data([](const uint8_t *data, std::size_t len) {
|
res.on_data([](const uint8_t *data, std::size_t len) {
|
||||||
|
|
|
@ -36,13 +36,15 @@ request::request() : impl_(make_unique<request_impl>()) {}
|
||||||
|
|
||||||
request::~request() {}
|
request::~request() {}
|
||||||
|
|
||||||
void request::cancel() { impl_->cancel(); }
|
void request::cancel() const { impl_->cancel(); }
|
||||||
|
|
||||||
void request::on_response(response_cb cb) { impl_->on_response(std::move(cb)); }
|
void request::on_response(response_cb cb) const {
|
||||||
|
impl_->on_response(std::move(cb));
|
||||||
|
}
|
||||||
|
|
||||||
void request::on_push(request_cb cb) { impl_->on_push(std::move(cb)); }
|
void request::on_push(request_cb cb) const { impl_->on_push(std::move(cb)); }
|
||||||
|
|
||||||
void request::on_close(close_cb cb) { impl_->on_close(std::move(cb)); }
|
void request::on_close(close_cb cb) const { impl_->on_close(std::move(cb)); }
|
||||||
|
|
||||||
const std::string &request::method() const { return impl_->method(); }
|
const std::string &request::method() const { return impl_->method(); }
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ response::response() : impl_(make_unique<response_impl>()) {}
|
||||||
|
|
||||||
response::~response() {}
|
response::~response() {}
|
||||||
|
|
||||||
void response::on_data(data_cb cb) { impl_->on_data(std::move(cb)); }
|
void response::on_data(data_cb cb) const { impl_->on_data(std::move(cb)); }
|
||||||
|
|
||||||
int response::status_code() const { return impl_->status_code(); }
|
int response::status_code() const { return impl_->status_code(); }
|
||||||
|
|
||||||
|
|
|
@ -57,22 +57,24 @@ void session::shutdown() { impl_->shutdown(); }
|
||||||
|
|
||||||
boost::asio::io_service &session::io_service() { return impl_->io_service(); }
|
boost::asio::io_service &session::io_service() { return impl_->io_service(); }
|
||||||
|
|
||||||
request *session::submit(boost::system::error_code &ec,
|
const request *session::submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method,
|
||||||
header_map h) {
|
const std::string &uri, header_map h) {
|
||||||
return impl_->submit(ec, method, uri, read_cb(), std::move(h));
|
return impl_->submit(ec, method, uri, read_cb(), std::move(h));
|
||||||
}
|
}
|
||||||
|
|
||||||
request *session::submit(boost::system::error_code &ec,
|
const request *session::submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method,
|
||||||
std::string data, header_map h) {
|
const std::string &uri, std::string data,
|
||||||
|
header_map h) {
|
||||||
return impl_->submit(ec, method, uri, string_reader(std::move(data)),
|
return impl_->submit(ec, method, uri, string_reader(std::move(data)),
|
||||||
std::move(h));
|
std::move(h));
|
||||||
}
|
}
|
||||||
|
|
||||||
request *session::submit(boost::system::error_code &ec,
|
const request *session::submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method,
|
||||||
read_cb cb, header_map h) {
|
const std::string &uri, read_cb cb,
|
||||||
|
header_map h) {
|
||||||
return impl_->submit(ec, method, uri, std::move(cb), std::move(h));
|
return impl_->submit(ec, method, uri, std::move(cb), std::move(h));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -358,9 +358,10 @@ std::unique_ptr<stream> session_impl::create_stream() {
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
|
|
||||||
request *session_impl::submit(boost::system::error_code &ec,
|
const request *session_impl::submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method,
|
||||||
read_cb cb, header_map h) {
|
const std::string &uri, read_cb cb,
|
||||||
|
header_map h) {
|
||||||
ec.clear();
|
ec.clear();
|
||||||
|
|
||||||
auto nva = std::vector<nghttp2_nv>();
|
auto nva = std::vector<nghttp2_nv>();
|
||||||
|
|
|
@ -66,8 +66,9 @@ public:
|
||||||
stream *create_push_stream(int32_t stream_id);
|
stream *create_push_stream(int32_t stream_id);
|
||||||
stream *find_stream(int32_t stream_id);
|
stream *find_stream(int32_t stream_id);
|
||||||
|
|
||||||
request *submit(boost::system::error_code &ec, const std::string &method,
|
const request *submit(boost::system::error_code &ec,
|
||||||
const std::string &uri, read_cb cb, header_map h);
|
const std::string &method, const std::string &uri,
|
||||||
|
read_cb cb, header_map h);
|
||||||
|
|
||||||
virtual void start_connect(tcp::resolver::iterator endpoint_it) = 0;
|
virtual void start_connect(tcp::resolver::iterator endpoint_it) = 0;
|
||||||
virtual tcp::socket &socket() = 0;
|
virtual tcp::socket &socket() = 0;
|
||||||
|
|
|
@ -287,7 +287,7 @@ public:
|
||||||
response();
|
response();
|
||||||
~response();
|
~response();
|
||||||
|
|
||||||
void on_data(data_cb cb);
|
void on_data(data_cb cb) const;
|
||||||
|
|
||||||
int status_code() const;
|
int status_code() const;
|
||||||
|
|
||||||
|
@ -303,8 +303,8 @@ private:
|
||||||
|
|
||||||
class request;
|
class request;
|
||||||
|
|
||||||
using response_cb = std::function<void(response &)>;
|
using response_cb = std::function<void(const response &)>;
|
||||||
using request_cb = std::function<void(request &)>;
|
using request_cb = std::function<void(const request &)>;
|
||||||
|
|
||||||
class request_impl;
|
class request_impl;
|
||||||
|
|
||||||
|
@ -313,11 +313,11 @@ public:
|
||||||
request();
|
request();
|
||||||
~request();
|
~request();
|
||||||
|
|
||||||
void on_response(response_cb cb);
|
void on_response(response_cb cb) const;
|
||||||
void on_push(request_cb cb);
|
void on_push(request_cb cb) const;
|
||||||
void on_close(close_cb cb);
|
void on_close(close_cb cb) const;
|
||||||
|
|
||||||
void cancel();
|
void cancel() const;
|
||||||
|
|
||||||
const std::string &method() const;
|
const std::string &method() const;
|
||||||
const std::string &scheme() const;
|
const std::string &scheme() const;
|
||||||
|
@ -351,12 +351,15 @@ public:
|
||||||
|
|
||||||
boost::asio::io_service &io_service();
|
boost::asio::io_service &io_service();
|
||||||
|
|
||||||
request *submit(boost::system::error_code &ec, const std::string &method,
|
const request *submit(boost::system::error_code &ec,
|
||||||
const std::string &uri, header_map h = {});
|
const std::string &method, const std::string &uri,
|
||||||
request *submit(boost::system::error_code &ec, const std::string &method,
|
header_map h = {});
|
||||||
const std::string &uri, std::string data, header_map h = {});
|
const request *submit(boost::system::error_code &ec,
|
||||||
request *submit(boost::system::error_code &ec, const std::string &method,
|
const std::string &method, const std::string &uri,
|
||||||
const std::string &uri, read_cb cb, header_map h = {});
|
std::string data, header_map h = {});
|
||||||
|
const request *submit(boost::system::error_code &ec,
|
||||||
|
const std::string &method, const std::string &uri,
|
||||||
|
read_cb cb, header_map h = {});
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<session_impl> impl_;
|
std::unique_ptr<session_impl> impl_;
|
||||||
|
|
Loading…
Reference in New Issue