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 "nghttp2_config.h"
27 #include <nghttp2/asio_http2_client.h>
29 #include "asio_client_session_tcp_impl.h"
30 #include "asio_client_session_tls_impl.h"
31 #include "asio_common.h"
35 namespace asio_http2 {
38 using boost::asio::ip::tcp;
40 session::session(boost::asio::io_service &io_service, const std::string &host,
41 const std::string &service)
42 : impl_(make_unique<session_tcp_impl>(io_service, host, service)) {}
44 session::session(boost::asio::io_service &io_service,
45 boost::asio::ssl::context &tls_ctx, const std::string &host,
46 const std::string &service)
47 : impl_(make_unique<session_tls_impl>(io_service, tls_ctx, host, service)) {
50 session::~session() {}
52 session::session(session &&other) noexcept : impl_(std::move(other.impl_)) {}
54 session &session::operator=(session &&other) noexcept {
59 impl_ = std::move(other.impl_);
63 void session::on_connect(connect_cb cb) const {
64 impl_->on_connect(std::move(cb));
67 void session::on_error(error_cb cb) const { impl_->on_error(std::move(cb)); }
69 void session::shutdown() const { impl_->shutdown(); }
71 boost::asio::io_service &session::io_service() const {
72 return impl_->io_service();
75 const request *session::submit(boost::system::error_code &ec,
76 const std::string &method,
77 const std::string &uri, header_map h) const {
78 return impl_->submit(ec, method, uri, generator_cb(), std::move(h));
81 const request *session::submit(boost::system::error_code &ec,
82 const std::string &method,
83 const std::string &uri, std::string data,
85 return impl_->submit(ec, method, uri, string_generator(std::move(data)),
89 const request *session::submit(boost::system::error_code &ec,
90 const std::string &method,
91 const std::string &uri, generator_cb cb,
93 return impl_->submit(ec, method, uri, std::move(cb), std::move(h));
97 } // namespace asio_http2