diff --git a/examples/asio-cl.cc b/examples/asio-cl.cc index ffb1d9a0..b8908265 100644 --- a/examples/asio-cl.cc +++ b/examples/asio-cl.cc @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) { return; } - req->on_response([&sess, req](response &res) { + req->on_response([&sess, req](const response &res) { std::cerr << "response header was received" << std::endl; print_header(res); @@ -87,12 +87,12 @@ int main(int argc, char *argv[]) { 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; 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; res.on_data([](const uint8_t *data, std::size_t len) { diff --git a/src/asio_client_request.cc b/src/asio_client_request.cc index b1194940..4aa83866 100644 --- a/src/asio_client_request.cc +++ b/src/asio_client_request.cc @@ -36,13 +36,15 @@ request::request() : impl_(make_unique()) {} 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(); } diff --git a/src/asio_client_response.cc b/src/asio_client_response.cc index 6c66ef16..e38355a0 100644 --- a/src/asio_client_response.cc +++ b/src/asio_client_response.cc @@ -36,7 +36,7 @@ response::response() : impl_(make_unique()) {} 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(); } diff --git a/src/asio_client_session.cc b/src/asio_client_session.cc index a060cf44..046a48a6 100644 --- a/src/asio_client_session.cc +++ b/src/asio_client_session.cc @@ -57,22 +57,24 @@ void session::shutdown() { impl_->shutdown(); } boost::asio::io_service &session::io_service() { return impl_->io_service(); } -request *session::submit(boost::system::error_code &ec, - const std::string &method, const std::string &uri, - header_map h) { +const request *session::submit(boost::system::error_code &ec, + const std::string &method, + const std::string &uri, header_map h) { return impl_->submit(ec, method, uri, read_cb(), std::move(h)); } -request *session::submit(boost::system::error_code &ec, - const std::string &method, const std::string &uri, - std::string data, header_map h) { +const request *session::submit(boost::system::error_code &ec, + const std::string &method, + const std::string &uri, std::string data, + header_map h) { return impl_->submit(ec, method, uri, string_reader(std::move(data)), std::move(h)); } -request *session::submit(boost::system::error_code &ec, - const std::string &method, const std::string &uri, - read_cb cb, header_map h) { +const request *session::submit(boost::system::error_code &ec, + const std::string &method, + const std::string &uri, read_cb cb, + header_map h) { return impl_->submit(ec, method, uri, std::move(cb), std::move(h)); } diff --git a/src/asio_client_session_impl.cc b/src/asio_client_session_impl.cc index 72153a19..58985380 100644 --- a/src/asio_client_session_impl.cc +++ b/src/asio_client_session_impl.cc @@ -358,9 +358,10 @@ std::unique_ptr session_impl::create_stream() { return strm; } -request *session_impl::submit(boost::system::error_code &ec, - const std::string &method, const std::string &uri, - read_cb cb, header_map h) { +const request *session_impl::submit(boost::system::error_code &ec, + const std::string &method, + const std::string &uri, read_cb cb, + header_map h) { ec.clear(); auto nva = std::vector(); diff --git a/src/asio_client_session_impl.h b/src/asio_client_session_impl.h index b3469b9c..913998cd 100644 --- a/src/asio_client_session_impl.h +++ b/src/asio_client_session_impl.h @@ -66,8 +66,9 @@ public: stream *create_push_stream(int32_t stream_id); stream *find_stream(int32_t stream_id); - request *submit(boost::system::error_code &ec, const std::string &method, - const std::string &uri, read_cb cb, 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); virtual void start_connect(tcp::resolver::iterator endpoint_it) = 0; virtual tcp::socket &socket() = 0; diff --git a/src/includes/nghttp2/asio_http2.h b/src/includes/nghttp2/asio_http2.h index 6df3f600..8c2a8033 100644 --- a/src/includes/nghttp2/asio_http2.h +++ b/src/includes/nghttp2/asio_http2.h @@ -287,7 +287,7 @@ public: response(); ~response(); - void on_data(data_cb cb); + void on_data(data_cb cb) const; int status_code() const; @@ -303,8 +303,8 @@ private: class request; -using response_cb = std::function; -using request_cb = std::function; +using response_cb = std::function; +using request_cb = std::function; class request_impl; @@ -313,11 +313,11 @@ public: request(); ~request(); - void on_response(response_cb cb); - void on_push(request_cb cb); - void on_close(close_cb cb); + void on_response(response_cb cb) const; + void on_push(request_cb cb) const; + void on_close(close_cb cb) const; - void cancel(); + void cancel() const; const std::string &method() const; const std::string &scheme() const; @@ -351,12 +351,15 @@ public: boost::asio::io_service &io_service(); - request *submit(boost::system::error_code &ec, const std::string &method, - const std::string &uri, header_map h = {}); - request *submit(boost::system::error_code &ec, const std::string &method, - const std::string &uri, std::string data, header_map h = {}); - request *submit(boost::system::error_code &ec, const std::string &method, - const std::string &uri, read_cb cb, header_map h = {}); + const request *submit(boost::system::error_code &ec, + const std::string &method, const std::string &uri, + header_map h = {}); + const request *submit(boost::system::error_code &ec, + const std::string &method, const std::string &uri, + 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: std::unique_ptr impl_;