2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2015 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "asio_client_request_impl.h"
27 #include "asio_client_stream.h"
28 #include "asio_client_session_impl.h"
32 namespace asio_http2 {
35 request_impl::request_impl() : strm_(nullptr) {}
37 void request_impl::write_trailer(header_map h) {
38 auto sess = strm_->session();
39 sess->write_trailer(*strm_, std::move(h));
42 void request_impl::cancel(uint32_t error_code) {
43 auto sess = strm_->session();
44 sess->cancel(*strm_, error_code);
47 void request_impl::on_response(response_cb cb) { response_cb_ = std::move(cb); }
49 void request_impl::call_on_response(response &res) {
55 void request_impl::on_push(request_cb cb) { push_request_cb_ = std::move(cb); }
57 void request_impl::call_on_push(request &push_req) {
58 if (push_request_cb_) {
59 push_request_cb_(push_req);
63 void request_impl::on_close(close_cb cb) { close_cb_ = std::move(cb); }
65 void request_impl::call_on_close(uint32_t error_code) {
67 close_cb_(error_code);
71 void request_impl::on_read(generator_cb cb) { generator_cb_ = std::move(cb); }
73 generator_cb::result_type request_impl::call_on_read(uint8_t *buf,
75 uint32_t *data_flags) {
77 return generator_cb_(buf, len, data_flags);
80 *data_flags |= NGHTTP2_DATA_FLAG_EOF;
85 void request_impl::resume() {
86 auto sess = strm_->session();
90 void request_impl::header(header_map h) { header_ = std::move(h); }
92 header_map &request_impl::header() { return header_; }
94 const header_map &request_impl::header() const { return header_; }
96 void request_impl::stream(class stream *strm) { strm_ = strm; }
98 void request_impl::uri(uri_ref uri) { uri_ = std::move(uri); }
100 const uri_ref &request_impl::uri() const { return uri_; }
102 uri_ref &request_impl::uri() { return uri_; }
104 void request_impl::method(std::string s) { method_ = std::move(s); }
106 const std::string &request_impl::method() const { return method_; }
108 } // namespace client
109 } // namespace asio_http2
110 } // namespace nghttp2