mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 10:35:50 +00:00
The message class now behaves like a pair with respect to the construction of the body and headers. Additional constructors allow construction of just the body portion from a tuple, leaving the headers default constructed. Previous constructors are removed as they were a notational convenience for assembling HTTP/1 requests and responses. They are not necessary as this library aims at library writers and not end users.
116 lines
2.9 KiB
C++
116 lines
2.9 KiB
C++
//
|
|
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
//
|
|
// 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)
|
|
//
|
|
|
|
#ifndef BEAST_HTTP_MESSAGE_V1_HPP
|
|
#define BEAST_HTTP_MESSAGE_V1_HPP
|
|
|
|
#include <beast/http/message.hpp>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace beast {
|
|
namespace http {
|
|
|
|
/** A HTTP/1 message.
|
|
|
|
A message can be a request or response, depending on the `isRequest`
|
|
template argument value. Requests and responses have different types,
|
|
so functions may be overloaded on them if desired.
|
|
|
|
The `Body` template argument type determines the model used
|
|
to read or write the content body of the message.
|
|
|
|
@tparam isRequest `true` if this is a request.
|
|
|
|
@tparam Body A type meeting the requirements of Body.
|
|
|
|
@tparam Headers A type meeting the requirements of Headers.
|
|
*/
|
|
template<bool isRequest, class Body, class Headers>
|
|
struct message_v1 : message<isRequest, Body, Headers>
|
|
{
|
|
/// HTTP/1 version (10 or 11)
|
|
int version;
|
|
|
|
/// Default constructor
|
|
message_v1() = default;
|
|
|
|
/// Constructor
|
|
template<class Arg1, class... Argn>
|
|
explicit
|
|
message_v1(Arg1& arg1, Argn&&... argn)
|
|
: message<isRequest, Body, Headers>(
|
|
std::forward<Arg1>(arg1),
|
|
std::forward<Argn>(argn)...)
|
|
{
|
|
}
|
|
};
|
|
|
|
#if ! GENERATING_DOCS
|
|
|
|
/// A typical HTTP/1 request
|
|
template<class Body,
|
|
class Headers = basic_headers<std::allocator<char>>>
|
|
using request_v1 = message_v1<true, Body, Headers>;
|
|
|
|
/// A typical HTTP/1 response
|
|
template<class Body,
|
|
class Headers = basic_headers<std::allocator<char>>>
|
|
using response_v1 = message_v1<false, Body, Headers>;
|
|
|
|
#endif
|
|
|
|
/// Returns `true` if a HTTP/1 message indicates a keep alive
|
|
template<bool isRequest, class Body, class Headers>
|
|
bool
|
|
is_keep_alive(message_v1<isRequest, Body, Headers> const& msg);
|
|
|
|
/// Returns `true` if a HTTP/1 message indicates an Upgrade request or response
|
|
template<bool isRequest, class Body, class Headers>
|
|
bool
|
|
is_upgrade(message_v1<isRequest, Body, Headers> const& msg);
|
|
|
|
/** HTTP/1 connection prepare options.
|
|
|
|
@note These values are used with @ref prepare.
|
|
*/
|
|
enum class connection
|
|
{
|
|
/// Specify Connection: close.
|
|
close,
|
|
|
|
/// Specify Connection: keep-alive where possible.
|
|
keep_alive,
|
|
|
|
/// Specify Connection: upgrade.
|
|
upgrade
|
|
};
|
|
|
|
/** Prepare a HTTP/1 message.
|
|
|
|
This function will adjust the Content-Length, Transfer-Encoding,
|
|
and Connection headers of the message based on the properties of
|
|
the body and the options passed in.
|
|
|
|
@param msg The message to prepare. The headers may be modified.
|
|
|
|
@param options A list of prepare options.
|
|
*/
|
|
template<
|
|
bool isRequest, class Body, class Headers,
|
|
class... Options>
|
|
void
|
|
prepare(message_v1<isRequest, Body, Headers>& msg,
|
|
Options&&... options);
|
|
|
|
} // http
|
|
} // beast
|
|
|
|
#include <beast/http/impl/message_v1.ipp>
|
|
|
|
#endif
|