2017-07-20 08:01:46 -07:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
//
|
|
|
|
|
|
2016-10-24 08:12:09 -04:00
|
|
|
#ifndef BEAST_WEBSOCKET_IMPL_HANDSHAKE_IPP
|
|
|
|
|
#define BEAST_WEBSOCKET_IMPL_HANDSHAKE_IPP
|
2017-07-20 08:01:46 -07:00
|
|
|
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
#include <beast/websocket/detail/type_traits.hpp>
|
2016-10-09 06:34:35 -04:00
|
|
|
#include <beast/http/message.hpp>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <beast/http/read.hpp>
|
|
|
|
|
#include <beast/http/write.hpp>
|
2017-01-05 09:07:18 -05:00
|
|
|
#include <beast/core/handler_helpers.hpp>
|
2017-01-02 13:29:48 -05:00
|
|
|
#include <beast/core/handler_ptr.hpp>
|
2016-10-24 08:12:09 -04:00
|
|
|
#include <beast/core/stream_concepts.hpp>
|
2016-09-25 12:17:32 -04:00
|
|
|
#include <boost/assert.hpp>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
namespace websocket {
|
|
|
|
|
|
2016-10-24 08:12:09 -04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
// send the upgrade request and process the response
|
|
|
|
|
//
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class Handler>
|
|
|
|
|
class stream<NextLayer>::handshake_op
|
|
|
|
|
{
|
|
|
|
|
struct data
|
|
|
|
|
{
|
2017-01-02 13:29:48 -05:00
|
|
|
bool cont;
|
2017-07-20 08:01:46 -07:00
|
|
|
stream<NextLayer>& ws;
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
response_type* res_p;
|
2017-04-29 15:50:05 -07:00
|
|
|
detail::sec_ws_key_type key;
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
request_type req;
|
|
|
|
|
response_type res;
|
2017-07-20 08:01:46 -07:00
|
|
|
int state = 0;
|
|
|
|
|
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
template<class Decorator>
|
2017-01-02 13:29:48 -05:00
|
|
|
data(Handler& handler, stream<NextLayer>& ws_,
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
response_type* res_p_,
|
|
|
|
|
boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
Decorator const& decorator)
|
2017-01-05 09:07:18 -05:00
|
|
|
: cont(beast_asio_helpers::
|
2017-01-02 13:29:48 -05:00
|
|
|
is_continuation(handler))
|
|
|
|
|
, ws(ws_)
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
, res_p(res_p_)
|
|
|
|
|
, req(ws.build_request(key,
|
|
|
|
|
host, resource, decorator))
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-05-15 16:22:25 -04:00
|
|
|
ws.reset();
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-02 13:29:48 -05:00
|
|
|
handler_ptr<data, Handler> d_;
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
handshake_op(handshake_op&&) = default;
|
|
|
|
|
handshake_op(handshake_op const&) = default;
|
|
|
|
|
|
|
|
|
|
template<class DeducedHandler, class... Args>
|
|
|
|
|
handshake_op(DeducedHandler&& h,
|
|
|
|
|
stream<NextLayer>& ws, Args&&... args)
|
2017-01-29 19:46:17 -05:00
|
|
|
: d_(std::forward<DeducedHandler>(h),
|
|
|
|
|
ws, std::forward<Args>(args)...)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-05-11 07:56:36 -04:00
|
|
|
(*this)(error_code{}, false);
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 07:56:36 -04:00
|
|
|
void
|
|
|
|
|
operator()(error_code ec, bool again = true);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
|
friend
|
|
|
|
|
void* asio_handler_allocate(
|
|
|
|
|
std::size_t size, handshake_op* op)
|
|
|
|
|
{
|
2017-01-05 09:07:18 -05:00
|
|
|
return beast_asio_helpers::
|
2017-01-02 13:29:48 -05:00
|
|
|
allocate(size, op->d_.handler());
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend
|
|
|
|
|
void asio_handler_deallocate(
|
|
|
|
|
void* p, std::size_t size, handshake_op* op)
|
|
|
|
|
{
|
2017-01-05 09:07:18 -05:00
|
|
|
return beast_asio_helpers::
|
2017-01-02 13:29:48 -05:00
|
|
|
deallocate(p, size, op->d_.handler());
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend
|
|
|
|
|
bool asio_handler_is_continuation(handshake_op* op)
|
|
|
|
|
{
|
|
|
|
|
return op->d_->cont;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 08:01:44 -04:00
|
|
|
template<class Function>
|
2017-07-20 08:01:46 -07:00
|
|
|
friend
|
|
|
|
|
void asio_handler_invoke(Function&& f, handshake_op* op)
|
|
|
|
|
{
|
2017-01-05 09:07:18 -05:00
|
|
|
return beast_asio_helpers::
|
2017-01-02 13:29:48 -05:00
|
|
|
invoke(f, op->d_.handler());
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class Handler>
|
|
|
|
|
void
|
2016-05-11 07:56:36 -04:00
|
|
|
stream<NextLayer>::handshake_op<Handler>::
|
|
|
|
|
operator()(error_code ec, bool again)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
auto& d = *d_;
|
|
|
|
|
d.cont = d.cont || again;
|
|
|
|
|
while(! ec && d.state != 99)
|
|
|
|
|
{
|
|
|
|
|
switch(d.state)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
{
|
|
|
|
|
// send http upgrade
|
|
|
|
|
d.state = 1;
|
|
|
|
|
// VFALCO Do we need the ability to move
|
|
|
|
|
// a message on the async_write?
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
//
|
2016-10-24 18:41:25 -04:00
|
|
|
pmd_read(
|
|
|
|
|
d.ws.pmd_config_, d.req.fields);
|
2017-07-20 08:01:46 -07:00
|
|
|
http::async_write(d.ws.stream_,
|
|
|
|
|
d.req, std::move(*this));
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
// TODO We don't need d.req now. Figure
|
|
|
|
|
// out a way to make it a parameter instead
|
|
|
|
|
// of a state variable to reduce footprint.
|
2017-07-20 08:01:46 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sent upgrade
|
|
|
|
|
case 1:
|
|
|
|
|
// read http response
|
|
|
|
|
d.state = 2;
|
2016-04-30 13:00:33 -04:00
|
|
|
http::async_read(d.ws.next_layer(),
|
2016-11-20 07:32:41 -05:00
|
|
|
d.ws.stream_.buffer(), d.res,
|
2017-07-20 08:01:46 -07:00
|
|
|
std::move(*this));
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// got response
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
2016-11-20 07:32:41 -05:00
|
|
|
d.ws.do_response(d.res, d.key, ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
// call handler
|
|
|
|
|
d.state = 99;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
if(d.res_p)
|
|
|
|
|
swap(d.res, *d.res_p);
|
2017-01-02 13:29:48 -05:00
|
|
|
d_.invoke(ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-24 08:12:09 -04:00
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class HandshakeHandler>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
typename async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)>::result_type
|
2016-10-24 08:12:09 -04:00
|
|
|
stream<NextLayer>::
|
|
|
|
|
async_handshake(boost::string_ref const& host,
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
HandshakeHandler&& handler)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
|
|
|
|
static_assert(is_AsyncStream<next_layer_type>::value,
|
|
|
|
|
"AsyncStream requirements not met");
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
beast::async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)> completion{handler};
|
2016-10-24 08:12:09 -04:00
|
|
|
handshake_op<decltype(completion.handler)>{
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
completion.handler, *this, nullptr,
|
|
|
|
|
host, resource, &default_decorate_req};
|
|
|
|
|
return completion.result.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class HandshakeHandler>
|
|
|
|
|
typename async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)>::result_type
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
async_handshake(response_type& res,
|
|
|
|
|
boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
HandshakeHandler&& handler)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_AsyncStream<next_layer_type>::value,
|
|
|
|
|
"AsyncStream requirements not met");
|
|
|
|
|
beast::async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)> completion{handler};
|
|
|
|
|
handshake_op<decltype(completion.handler)>{
|
|
|
|
|
completion.handler, *this, &res,
|
|
|
|
|
host, resource, &default_decorate_req};
|
|
|
|
|
return completion.result.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class RequestDecorator, class HandshakeHandler>
|
|
|
|
|
typename async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)>::result_type
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
async_handshake_ex(boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
|
HandshakeHandler&& handler)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_AsyncStream<next_layer_type>::value,
|
|
|
|
|
"AsyncStream requirements not met");
|
|
|
|
|
static_assert(detail::is_RequestDecorator<
|
|
|
|
|
RequestDecorator>::value,
|
|
|
|
|
"RequestDecorator requirements not met");
|
|
|
|
|
beast::async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)> completion{handler};
|
|
|
|
|
handshake_op<decltype(completion.handler)>{
|
|
|
|
|
completion.handler, *this, nullptr,
|
|
|
|
|
host, resource, decorator};
|
|
|
|
|
return completion.result.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class RequestDecorator, class HandshakeHandler>
|
|
|
|
|
typename async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)>::result_type
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
async_handshake_ex(response_type& res,
|
|
|
|
|
boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
|
HandshakeHandler&& handler)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_AsyncStream<next_layer_type>::value,
|
|
|
|
|
"AsyncStream requirements not met");
|
|
|
|
|
static_assert(detail::is_RequestDecorator<
|
|
|
|
|
RequestDecorator>::value,
|
|
|
|
|
"RequestDecorator requirements not met");
|
|
|
|
|
beast::async_completion<HandshakeHandler,
|
|
|
|
|
void(error_code)> completion{handler};
|
|
|
|
|
handshake_op<decltype(completion.handler)>{
|
|
|
|
|
completion.handler, *this, &res,
|
|
|
|
|
host, resource, decorator};
|
2016-10-24 08:12:09 -04:00
|
|
|
return completion.result.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
handshake(boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
|
|
|
|
error_code ec;
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
handshake(
|
|
|
|
|
host, resource, ec);
|
2016-10-24 08:12:09 -04:00
|
|
|
if(ec)
|
|
|
|
|
throw system_error{ec};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
handshake(response_type& res,
|
|
|
|
|
boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
error_code ec;
|
|
|
|
|
handshake(res, host, resource, ec);
|
2016-10-24 08:12:09 -04:00
|
|
|
if(ec)
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
throw system_error{ec};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class RequestDecorator>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
handshake_ex(boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
RequestDecorator const& decorator)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
|
|
|
|
static_assert(detail::is_RequestDecorator<
|
|
|
|
|
RequestDecorator>::value,
|
|
|
|
|
"RequestDecorator requirements not met");
|
|
|
|
|
error_code ec;
|
|
|
|
|
handshake_ex(host, resource, decorator, ec);
|
2016-10-24 08:12:09 -04:00
|
|
|
if(ec)
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
throw system_error{ec};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class RequestDecorator>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
handshake_ex(response_type& res,
|
|
|
|
|
boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
RequestDecorator const& decorator)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
|
|
|
|
static_assert(detail::is_RequestDecorator<
|
|
|
|
|
RequestDecorator>::value,
|
|
|
|
|
"RequestDecorator requirements not met");
|
|
|
|
|
error_code ec;
|
|
|
|
|
handshake_ex(res, host, resource, decorator, ec);
|
|
|
|
|
if(ec)
|
|
|
|
|
throw system_error{ec};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
handshake(boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource, error_code& ec)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
|
|
|
|
do_handshake(nullptr,
|
|
|
|
|
host, resource, &default_decorate_req, ec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
handshake(response_type& res,
|
|
|
|
|
boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
error_code& ec)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
|
|
|
|
do_handshake(&res,
|
|
|
|
|
host, resource, &default_decorate_req, ec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class RequestDecorator>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
handshake_ex(boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
|
error_code& ec)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
|
|
|
|
static_assert(detail::is_RequestDecorator<
|
|
|
|
|
RequestDecorator>::value,
|
|
|
|
|
"RequestDecorator requirements not met");
|
|
|
|
|
do_handshake(nullptr,
|
|
|
|
|
host, resource, decorator, ec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
|
template<class RequestDecorator>
|
|
|
|
|
void
|
|
|
|
|
stream<NextLayer>::
|
|
|
|
|
handshake_ex(response_type& res,
|
|
|
|
|
boost::string_ref const& host,
|
|
|
|
|
boost::string_ref const& resource,
|
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
|
error_code& ec)
|
|
|
|
|
{
|
|
|
|
|
static_assert(is_SyncStream<next_layer_type>::value,
|
|
|
|
|
"SyncStream requirements not met");
|
|
|
|
|
static_assert(detail::is_RequestDecorator<
|
|
|
|
|
RequestDecorator>::value,
|
|
|
|
|
"RequestDecorator requirements not met");
|
|
|
|
|
do_handshake(&res,
|
|
|
|
|
host, resource, decorator, ec);
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
} // websocket
|
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
|
|
#endif
|