36template <
typename PARENT,
39 typename REQUEST_REPLY,
40 typename CONTENT_INFO,
41 typename CONTENT_LENGTH_TYPE,
42 typename REFCOUNT_BASE>
60 rr_status = REQUEST_REPLY::Parser::pending;
181 static_assert(CONTENT_LENGTH_TYPE(-1) < CONTENT_LENGTH_TYPE(0),
"CONTENT_LENGTH_TYPE must be signed");
206 parent().base_http_content_out_needed();
270 return *
static_cast<PARENT *
>(
this);
303#if defined(OPENVPN_DEBUG_HTTP)
312 throw http_exception(
"unknown write status from SSL layer");
321#if defined(OPENVPN_DEBUG_HTTP)
324 if (
parent().base_link_send(buf))
333 parent().base_http_out_eof();
353 parent().base_error_handler(STATUS::E_CONTENT_SIZE,
"HTTP content too large");
356 parent().base_http_content_in(buf);
366#if defined(OPENVPN_DEBUG_HTTP)
370 if (
rr_status == REQUEST_REPLY::Parser::pending)
373 for (
size_t i = 0; i < buf.
size(); ++i)
376 if (
rr_status == REQUEST_REPLY::Parser::pending)
385 parent().base_error_handler(STATUS::E_HEADER_SIZE,
"HTTP headers too large");
394 if (
rr_status == REQUEST_REPLY::Parser::success)
402 if (!
parent().base_http_headers_received())
407 parent().base_http_done_handler(buf,
true);
414 parent().base_error_handler(STATUS::E_HTTP,
"HTTP headers parse error");
421 if (
rr_status == REQUEST_REPLY::Parser::success)
434 if (needed <= buf.
size())
437 if (needed < buf.
size())
451 parent().base_http_done_handler(residual,
false);
461 parent().base_link_send(*buf);
491 parent().base_error_handler(STATUS::E_EOF_SSL,
"SSL PEER_CLOSE_NOTIFY");
493 throw http_exception(
"unknown read status from SSL layer");
507 return CONTENT_INFO::CHUNKED;
512 if (content_length_str.empty())
514 const CONTENT_LENGTH_TYPE
content_length = parse_number_throw<CONTENT_LENGTH_TYPE>(content_length_str,
"content-length");
516 throw number_parse_exception(
"content-length is < 0");
void swap(BufferAllocatedType< T_ > &other)
Swaps the contents of this BufferAllocatedType object with another BufferAllocatedType object.
bool defined() const
Returns true if the buffer is not empty.
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
void advance(const size_t delta)
Advances the buffer by the specified delta.
bool empty() const
Returns true if the buffer is empty.
void write(const T *data, const size_t size)
Write data to the buffer.
auto * read_alloc(const size_t size)
Allocate memory and read data from the buffer into the allocated memory.
void set_size(const size_t size)
After an external method, operating on the array as a mutable unsigned char buffer,...
size_t prepare(Buffer &buf) const
size_t prepare(const unsigned int context, Buffer &buf) const
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
static Ptr Create(ArgsT &&...args)
Creates a new instance of RcEnable with the given arguments.
virtual void write_ciphertext(const BufferPtr &buf)=0
virtual void mark_no_cache()=0
virtual bool read_ciphertext_ready() const =0
virtual bool read_cleartext_ready() const =0
virtual std::string ssl_handshake_details() const =0
virtual bool did_full_handshake()=0
virtual BufferPtr read_ciphertext()=0
virtual ssize_t write_cleartext_unbuffered(const void *data, const size_t size)=0
virtual ssize_t read_cleartext(void *data, const size_t capacity)=0
virtual void error(const size_t type, const std::string *text=nullptr)
static BufferPtr transmit(BufferPtr buf)
bool http_in_started() const
bool http_out_started() const
const HTTP::HeaderList & headers() const
void chunked_content_in(BufferAllocated &buf)
void http_content_out_finish(BufferPtr buf)
CONTENT_LENGTH_TYPE rr_content_bytes
bool is_websocket() const
void tcp_in(BufferAllocated &b)
REQUEST_REPLY::Parser::status rr_status
void http_in(BufferAllocated &buf)
REQUEST_REPLY::Parser rr_parser
bool ssl_did_full_handshake() const
void reduce_max_content_bytes(const CONTENT_LENGTH_TYPE new_max_content_bytes)
CONTENT_LENGTH_TYPE rr_limit_bytes
HTTPBase(const typename CONFIG::Ptr &config_arg)
static CONTENT_LENGTH_TYPE get_content_length(const HTTP::HeaderList &headers)
void set_async_out(const bool async_out_arg)
CONTENT_LENGTH_TYPE rr_content_length
olong content_length() const
REQUEST_REPLY::State rr_obj
std::string ssl_handshake_details() const
std::unique_ptr< ChunkedHelper > rr_chunked
CONTENT_INFO content_info
const REQUEST_REPLY::State & request_reply() const
CONTENT_LENGTH_TYPE max_content_bytes
size_t http_buf_size() const
unsigned int rr_header_bytes
const CONFIG & http_config() const
static std::string http_out_state_string(const HTTPOutState hos)
void do_http_content_in(BufferAllocated &buf)
#define OPENVPN_EXCEPTION(C)
#define OPENVPN_THROW(exc, stuff)
#define OPENVPN_LOG(args)
int strcasecmp(const char *s1, const char *s2)
std::string buf_to_string(const Buffer &buf)