Make request, response const

This commit is contained in:
Tatsuhiro Tsujikawa 2015-03-04 00:20:09 +09:00
parent 0676535caf
commit 8afd75ca47
7 changed files with 44 additions and 35 deletions

View File

@ -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) {

View File

@ -36,13 +36,15 @@ request::request() : impl_(make_unique<request_impl>()) {}
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(); }

View File

@ -36,7 +36,7 @@ response::response() : impl_(make_unique<response_impl>()) {}
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(); }

View File

@ -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));
}

View File

@ -358,9 +358,10 @@ std::unique_ptr<stream> 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<nghttp2_nv>();

View File

@ -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;

View File

@ -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<void(response &)>;
using request_cb = std::function<void(request &)>;
using response_cb = std::function<void(const response &)>;
using request_cb = std::function<void(const request &)>;
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<session_impl> impl_;