asio: Separate client API to asio_http2_client.h
This commit is contained in:
parent
76eab3faa0
commit
2fa28e790d
|
@ -26,10 +26,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#include <nghttp2/nghttp2.h>
|
|
||||||
#include <nghttp2/asio_http2.h>
|
|
||||||
|
|
||||||
using boost::asio::ip::tcp;
|
using boost::asio::ip::tcp;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <nghttp2/asio_http2.h>
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#include "asio_client_request_impl.h"
|
#include "asio_client_request_impl.h"
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include "nghttp2_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
namespace asio_http2 {
|
namespace asio_http2 {
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <nghttp2/asio_http2.h>
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#include "asio_client_response_impl.h"
|
#include "asio_client_response_impl.h"
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include "nghttp2_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
namespace asio_http2 {
|
namespace asio_http2 {
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
#include "nghttp2_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#include "asio_client_session_tcp_impl.h"
|
#include "asio_client_session_tcp_impl.h"
|
||||||
#include "asio_client_session_tls_impl.h"
|
#include "asio_client_session_tls_impl.h"
|
||||||
|
|
|
@ -27,13 +27,7 @@
|
||||||
|
|
||||||
#include "nghttp2_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <map>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
|
||||||
|
|
||||||
#include <nghttp2/nghttp2.h>
|
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
|
||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
namespace asio_http2 {
|
namespace asio_http2 {
|
||||||
|
|
|
@ -27,9 +27,7 @@
|
||||||
|
|
||||||
#include "asio_client_session_impl.h"
|
#include "asio_client_session_impl.h"
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
|
||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
namespace asio_http2 {
|
namespace asio_http2 {
|
||||||
|
|
|
@ -27,9 +27,7 @@
|
||||||
|
|
||||||
#include "asio_client_session_impl.h"
|
#include "asio_client_session_impl.h"
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
|
||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
namespace asio_http2 {
|
namespace asio_http2 {
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include "nghttp2_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
namespace asio_http2 {
|
namespace asio_http2 {
|
||||||
|
|
|
@ -27,6 +27,6 @@
|
||||||
|
|
||||||
#include "nghttp2_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <nghttp2/asio_http2.h>
|
#include <nghttp2/asio_http2_client.h>
|
||||||
|
|
||||||
#endif // ASIO_CLIENT_TLS_CONTEXT_H
|
#endif // ASIO_CLIENT_TLS_CONTEXT_H
|
||||||
|
|
|
@ -20,4 +20,4 @@
|
||||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
nobase_include_HEADERS = nghttp2/asio_http2.h
|
nobase_include_HEADERS = nghttp2/asio_http2.h nghttp2/asio_http2_client.h
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
#include <boost/system/error_code.hpp>
|
#include <boost/system/error_code.hpp>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/asio/ssl.hpp>
|
|
||||||
|
|
||||||
#include <nghttp2/nghttp2.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
|
@ -287,99 +286,6 @@ std::string percent_decode(const std::string &s);
|
||||||
// Returns HTTP date representation of current posix time |t|.
|
// Returns HTTP date representation of current posix time |t|.
|
||||||
std::string http_date(int64_t t);
|
std::string http_date(int64_t t);
|
||||||
|
|
||||||
namespace client {
|
|
||||||
|
|
||||||
class response_impl;
|
|
||||||
|
|
||||||
class response {
|
|
||||||
public:
|
|
||||||
response();
|
|
||||||
~response();
|
|
||||||
|
|
||||||
void on_data(data_cb cb) const;
|
|
||||||
|
|
||||||
int status_code() const;
|
|
||||||
|
|
||||||
int64_t content_length() const;
|
|
||||||
|
|
||||||
const header_map &header() const;
|
|
||||||
|
|
||||||
response_impl &impl();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<response_impl> impl_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class request;
|
|
||||||
|
|
||||||
using response_cb = std::function<void(const response &)>;
|
|
||||||
using request_cb = std::function<void(const request &)>;
|
|
||||||
using connect_cb =
|
|
||||||
std::function<void(boost::asio::ip::tcp::resolver::iterator)>;
|
|
||||||
|
|
||||||
class request_impl;
|
|
||||||
|
|
||||||
class request {
|
|
||||||
public:
|
|
||||||
request();
|
|
||||||
~request();
|
|
||||||
|
|
||||||
void on_response(response_cb cb) const;
|
|
||||||
void on_push(request_cb cb) const;
|
|
||||||
void on_close(close_cb cb) const;
|
|
||||||
|
|
||||||
void cancel() const;
|
|
||||||
|
|
||||||
const std::string &method() const;
|
|
||||||
|
|
||||||
const uri_ref &uri() const;
|
|
||||||
|
|
||||||
const header_map &header() const;
|
|
||||||
|
|
||||||
request_impl &impl();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<request_impl> impl_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class session_impl;
|
|
||||||
|
|
||||||
class session {
|
|
||||||
public:
|
|
||||||
session(boost::asio::io_service &io_service, const std::string &host,
|
|
||||||
const std::string &service);
|
|
||||||
session(boost::asio::io_service &io_service,
|
|
||||||
boost::asio::ssl::context &tls_context, const std::string &host,
|
|
||||||
const std::string &service);
|
|
||||||
~session();
|
|
||||||
|
|
||||||
void on_connect(connect_cb cb);
|
|
||||||
void on_error(error_cb cb);
|
|
||||||
|
|
||||||
void shutdown();
|
|
||||||
|
|
||||||
boost::asio::io_service &io_service();
|
|
||||||
|
|
||||||
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_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// configure |tls_ctx| for client use. Currently, we just set NPN
|
|
||||||
// callback for HTTP/2.
|
|
||||||
void configure_tls_context(boost::asio::ssl::context &tls_ctx);
|
|
||||||
|
|
||||||
} // namespace client
|
|
||||||
|
|
||||||
} // namespace asio_http2
|
} // namespace asio_http2
|
||||||
|
|
||||||
} // namespace nghttp2
|
} // namespace nghttp2
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
/*
|
||||||
|
* nghttp2 - HTTP/2 C Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Tatsuhiro Tsujikawa
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef ASIO_HTTP2_CLIENT_H
|
||||||
|
#define ASIO_HTTP2_CLIENT_H
|
||||||
|
|
||||||
|
#include <nghttp2/asio_http2.h>
|
||||||
|
|
||||||
|
#include <boost/asio/ssl.hpp>
|
||||||
|
|
||||||
|
namespace nghttp2 {
|
||||||
|
|
||||||
|
namespace asio_http2 {
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
class response_impl;
|
||||||
|
|
||||||
|
class response {
|
||||||
|
public:
|
||||||
|
response();
|
||||||
|
~response();
|
||||||
|
|
||||||
|
void on_data(data_cb cb) const;
|
||||||
|
|
||||||
|
int status_code() const;
|
||||||
|
|
||||||
|
int64_t content_length() const;
|
||||||
|
|
||||||
|
const header_map &header() const;
|
||||||
|
|
||||||
|
response_impl &impl();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<response_impl> impl_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class request;
|
||||||
|
|
||||||
|
using response_cb = std::function<void(const response &)>;
|
||||||
|
using request_cb = std::function<void(const request &)>;
|
||||||
|
using connect_cb =
|
||||||
|
std::function<void(boost::asio::ip::tcp::resolver::iterator)>;
|
||||||
|
|
||||||
|
class request_impl;
|
||||||
|
|
||||||
|
class request {
|
||||||
|
public:
|
||||||
|
request();
|
||||||
|
~request();
|
||||||
|
|
||||||
|
void on_response(response_cb cb) const;
|
||||||
|
void on_push(request_cb cb) const;
|
||||||
|
void on_close(close_cb cb) const;
|
||||||
|
|
||||||
|
void cancel() const;
|
||||||
|
|
||||||
|
const std::string &method() const;
|
||||||
|
|
||||||
|
const uri_ref &uri() const;
|
||||||
|
|
||||||
|
const header_map &header() const;
|
||||||
|
|
||||||
|
request_impl &impl();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<request_impl> impl_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class session_impl;
|
||||||
|
|
||||||
|
class session {
|
||||||
|
public:
|
||||||
|
session(boost::asio::io_service &io_service, const std::string &host,
|
||||||
|
const std::string &service);
|
||||||
|
session(boost::asio::io_service &io_service,
|
||||||
|
boost::asio::ssl::context &tls_context, const std::string &host,
|
||||||
|
const std::string &service);
|
||||||
|
~session();
|
||||||
|
|
||||||
|
void on_connect(connect_cb cb);
|
||||||
|
void on_error(error_cb cb);
|
||||||
|
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
boost::asio::io_service &io_service();
|
||||||
|
|
||||||
|
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_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// configure |tls_ctx| for client use. Currently, we just set NPN
|
||||||
|
// callback for HTTP/2.
|
||||||
|
void configure_tls_context(boost::asio::ssl::context &tls_ctx);
|
||||||
|
|
||||||
|
} // namespace client
|
||||||
|
|
||||||
|
} // namespace asio_http2
|
||||||
|
|
||||||
|
} // namespace nghttp2
|
||||||
|
|
||||||
|
#endif // ASIO_HTTP2_CLIENT_H
|
Loading…
Reference in New Issue