diff --git a/src/asio_client_request.cc b/src/asio_client_request.cc index 0db73c59..4e2ee6a1 100644 --- a/src/asio_client_request.cc +++ b/src/asio_client_request.cc @@ -38,7 +38,7 @@ request::request() : impl_(make_unique()) {} request::~request() {} -void request::cancel() const { impl_->cancel(); } +void request::cancel(uint32_t error_code) const { impl_->cancel(error_code); } void request::on_response(response_cb cb) const { impl_->on_response(std::move(cb)); diff --git a/src/asio_client_request_impl.cc b/src/asio_client_request_impl.cc index 10a17e3f..a29d1917 100644 --- a/src/asio_client_request_impl.cc +++ b/src/asio_client_request_impl.cc @@ -33,7 +33,7 @@ namespace client { request_impl::request_impl() : strm_(nullptr) {} -void request_impl::cancel() { strm_->cancel(); } +void request_impl::cancel(uint32_t error_code) { strm_->cancel(error_code); } void request_impl::on_response(response_cb cb) { response_cb_ = std::move(cb); } diff --git a/src/asio_client_request_impl.h b/src/asio_client_request_impl.h index f9e6b67f..176715f1 100644 --- a/src/asio_client_request_impl.h +++ b/src/asio_client_request_impl.h @@ -43,7 +43,7 @@ public: request_impl(const request_impl &) = delete; request_impl &operator=(const request_impl &) = delete; - void cancel(); + void cancel(uint32_t error_code); void on_response(response_cb cb); void call_on_response(response &res); diff --git a/src/asio_client_session_impl.cc b/src/asio_client_session_impl.cc index 2b60280a..c1b19f97 100644 --- a/src/asio_client_session_impl.cc +++ b/src/asio_client_session_impl.cc @@ -44,11 +44,11 @@ session_impl::session_impl(boost::asio::io_service &io_service) writing_(false), inside_callback_(false) {} session_impl::~session_impl() { - // finish up all active stream with CANCEL error code + // finish up all active stream for (auto &p : streams_) { auto &strm = p.second; auto &req = strm->request().impl(); - req.call_on_close(NGHTTP2_CANCEL); + req.call_on_close(NGHTTP2_INTERNAL_ERROR); } nghttp2_session_del(session_); @@ -321,9 +321,9 @@ bool session_impl::setup_session() { return true; } -void session_impl::cancel(stream &strm) { +void session_impl::cancel(stream &strm, uint32_t error_code) { nghttp2_submit_rst_stream(session_, NGHTTP2_FLAG_NONE, strm.stream_id(), - NGHTTP2_CANCEL); + error_code); signal_write(); } diff --git a/src/asio_client_session_impl.h b/src/asio_client_session_impl.h index 7a84a2e3..55042960 100644 --- a/src/asio_client_session_impl.h +++ b/src/asio_client_session_impl.h @@ -53,7 +53,7 @@ public: const connect_cb &on_connect() const; const error_cb &on_error() const; - void cancel(stream &strm); + void cancel(stream &strm, uint32_t error_code); std::unique_ptr create_stream(); std::unique_ptr pop_stream(int32_t stream_id); diff --git a/src/asio_client_stream.cc b/src/asio_client_stream.cc index 0b32e52b..80de501a 100644 --- a/src/asio_client_stream.cc +++ b/src/asio_client_stream.cc @@ -36,7 +36,7 @@ stream::stream(session_impl *sess) : sess_(sess), stream_id_(0) { request_.impl().stream(this); } -void stream::cancel() { sess_->cancel(*this); } +void stream::cancel(uint32_t error_code) { sess_->cancel(*this, error_code); } void stream::stream_id(int32_t stream_id) { stream_id_ = stream_id; } diff --git a/src/asio_client_stream.h b/src/asio_client_stream.h index 51fe9a8f..db9e075e 100644 --- a/src/asio_client_stream.h +++ b/src/asio_client_stream.h @@ -44,7 +44,7 @@ public: stream(const stream &) = delete; stream &operator=(const stream &) = delete; - void cancel(); + void cancel(uint32_t error_code); void stream_id(int32_t stream_id); int32_t stream_id() const; diff --git a/src/asio_http2_handler.cc b/src/asio_http2_handler.cc index 3437b0f1..334be504 100644 --- a/src/asio_http2_handler.cc +++ b/src/asio_http2_handler.cc @@ -65,7 +65,7 @@ void response::end(read_cb cb) const { impl_->end(std::move(cb)); } void response::on_close(close_cb cb) const { impl_->on_close(std::move(cb)); } -void response::cancel() const { impl_->cancel(); } +void response::cancel(uint32_t error_code) const { impl_->cancel(error_code); } const response *response::push(boost::system::error_code &ec, std::string method, std::string path, @@ -145,10 +145,10 @@ void response_impl::call_on_close(uint32_t error_code) { } } -void response_impl::cancel() { +void response_impl::cancel(uint32_t error_code) { auto handler = stream_->handler(); - handler->stream_error(stream_->get_stream_id(), NGHTTP2_CANCEL); + handler->stream_error(stream_->get_stream_id(), error_code); } void response_impl::start_response() { diff --git a/src/asio_http2_handler.h b/src/asio_http2_handler.h index c8d49898..84c204ad 100644 --- a/src/asio_http2_handler.h +++ b/src/asio_http2_handler.h @@ -79,7 +79,7 @@ public: void on_close(close_cb cb); void resume(); - void cancel(); + void cancel(uint32_t error_code); response *push(boost::system::error_code &ec, std::string method, std::string raw_path_query, header_map h = {}) const; diff --git a/src/includes/nghttp2/asio_http2_client.h b/src/includes/nghttp2/asio_http2_client.h index 02bae8c6..de15430e 100644 --- a/src/includes/nghttp2/asio_http2_client.h +++ b/src/includes/nghttp2/asio_http2_client.h @@ -72,7 +72,7 @@ public: void on_push(request_cb cb) const; void on_close(close_cb cb) const; - void cancel() const; + void cancel(uint32_t error_code = NGHTTP2_INTERNAL_ERROR) const; const std::string &method() const; diff --git a/src/includes/nghttp2/asio_http2_server.h b/src/includes/nghttp2/asio_http2_server.h index f669fa64..ee7f3f55 100644 --- a/src/includes/nghttp2/asio_http2_server.h +++ b/src/includes/nghttp2/asio_http2_server.h @@ -80,7 +80,7 @@ public: void on_close(close_cb cb) const; - void cancel() const; + void cancel(uint32_t error_code = NGHTTP2_INTERNAL_ERROR) const; // Resumes deferred response. void resume() const;