Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::http::h2::Http2Session Class Reference

#include <Http2Session.hpp>

Inheritance diagram for orbit::http::h2::Http2Session:
Collaboration diagram for orbit::http::h2::Http2Session:

Classes

struct  StreamContext
 

Public Member Functions

 Http2Session (std::weak_ptr< server::Connection > connection, network::Proactor &proactor, const routing::Router &router, concurrency::ThreadPool &thread_pool, std::string client_ip, size_t max_body_size)
 
 ~Http2Session ()
 
void process_data (const uint8_t *data, size_t len)
 
void send_pending ()
 
void begin_shutdown ()
 Sends GOAWAY: the client opens no new streams; open ones may finish.
 
bool idle ()
 True if no stream is open.
 
void close_streams ()
 The connection is gone: every open stream's writer reports closed.
 
void submit_response (int32_t stream_id, http::HttpResponse &response, bool has_body, bool streaming=false)
 Thread-safe API to submit an HTTP/2 response.
 
void submit_data (int32_t stream_id, std::string_view chunk)
 Appends chunk to a streaming response (see Http2ResponseWriter::send_headers).
 
void end_stream (int32_t stream_id)
 Ends a streaming response.
 
network::Proactor & proactor ()
 
concurrency::ThreadPool & thread_pool ()
 

Private Member Functions

void dispatch_request (std::shared_ptr< StreamContext > stream_ctx)
 
void submit_status_locked (int32_t stream_id, http::HttpStatus status)
 

Static Private Member Functions

static int on_begin_headers (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
 
static int on_header (nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, void *user_data)
 
static int on_frame_recv (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
 
static int on_data_chunk_recv (nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *user_data)
 
static int on_stream_close (nghttp2_session *session, int32_t stream_id, uint32_t error_code, void *user_data)
 
static ssize_t send_callback (nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data)
 
static ssize_t data_provider_read (nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, uint32_t *data_flags, nghttp2_data_source *source, void *user_data)
 

Private Attributes

std::weak_ptr< server::Connection > connection_
 
network::Proactor & proactor_
 
const routing::Router & router_
 
concurrency::ThreadPool & thread_pool_
 
std::string client_ip_
 
size_t max_body_size_
 
nghttp2_session * session_ {nullptr}
 
std::mutex session_mutex_
 
std::unordered_map< int32_t, std::shared_ptr< StreamContext > > streams_
 

Constructor & Destructor Documentation

◆ Http2Session()

orbit::http::h2::Http2Session::Http2Session ( std::weak_ptr< server::Connection >  connection,
network::Proactor &  proactor,
const routing::Router &  router,
concurrency::ThreadPool &  thread_pool,
std::string  client_ip,
size_t  max_body_size 
)

◆ ~Http2Session()

orbit::http::h2::Http2Session::~Http2Session ( )

Member Function Documentation

◆ begin_shutdown()

void orbit::http::h2::Http2Session::begin_shutdown ( )

Sends GOAWAY: the client opens no new streams; open ones may finish.

◆ close_streams()

void orbit::http::h2::Http2Session::close_streams ( )

The connection is gone: every open stream's writer reports closed.

◆ data_provider_read()

static ssize_t orbit::http::h2::Http2Session::data_provider_read ( nghttp2_session *  session,
int32_t  stream_id,
uint8_t *  buf,
size_t  length,
uint32_t *  data_flags,
nghttp2_data_source *  source,
void *  user_data 
)
staticprivate

◆ dispatch_request()

void orbit::http::h2::Http2Session::dispatch_request ( std::shared_ptr< StreamContext >  stream_ctx)
private

◆ end_stream()

void orbit::http::h2::Http2Session::end_stream ( int32_t  stream_id)

Ends a streaming response.

◆ idle()

bool orbit::http::h2::Http2Session::idle ( )

True if no stream is open.

◆ on_begin_headers()

static int orbit::http::h2::Http2Session::on_begin_headers ( nghttp2_session *  session,
const nghttp2_frame *  frame,
void *  user_data 
)
staticprivate

◆ on_data_chunk_recv()

static int orbit::http::h2::Http2Session::on_data_chunk_recv ( nghttp2_session *  session,
uint8_t  flags,
int32_t  stream_id,
const uint8_t *  data,
size_t  len,
void *  user_data 
)
staticprivate

◆ on_frame_recv()

static int orbit::http::h2::Http2Session::on_frame_recv ( nghttp2_session *  session,
const nghttp2_frame *  frame,
void *  user_data 
)
staticprivate

◆ on_header()

static int orbit::http::h2::Http2Session::on_header ( nghttp2_session *  session,
const nghttp2_frame *  frame,
const uint8_t *  name,
size_t  namelen,
const uint8_t *  value,
size_t  valuelen,
uint8_t  flags,
void *  user_data 
)
staticprivate

◆ on_stream_close()

static int orbit::http::h2::Http2Session::on_stream_close ( nghttp2_session *  session,
int32_t  stream_id,
uint32_t  error_code,
void *  user_data 
)
staticprivate

◆ proactor()

network::Proactor & orbit::http::h2::Http2Session::proactor ( )
inline

◆ process_data()

void orbit::http::h2::Http2Session::process_data ( const uint8_t *  data,
size_t  len 
)

◆ send_callback()

static ssize_t orbit::http::h2::Http2Session::send_callback ( nghttp2_session *  session,
const uint8_t *  data,
size_t  length,
int  flags,
void *  user_data 
)
staticprivate

◆ send_pending()

void orbit::http::h2::Http2Session::send_pending ( )

◆ submit_data()

void orbit::http::h2::Http2Session::submit_data ( int32_t  stream_id,
std::string_view  chunk 
)

Appends chunk to a streaming response (see Http2ResponseWriter::send_headers).

◆ submit_response()

void orbit::http::h2::Http2Session::submit_response ( int32_t  stream_id,
http::HttpResponse &  response,
bool  has_body,
bool  streaming = false 
)

Thread-safe API to submit an HTTP/2 response.

Parameters
stream_idThe HTTP/2 stream identifier.
responseThe HttpResponse to send.
has_bodyTrue if the response includes a body. Takes ownership of response.file_fd when a file body is sent.

◆ submit_status_locked()

void orbit::http::h2::Http2Session::submit_status_locked ( int32_t  stream_id,
http::HttpStatus  status 
)
private

◆ thread_pool()

concurrency::ThreadPool & orbit::http::h2::Http2Session::thread_pool ( )
inline

Member Data Documentation

◆ client_ip_

std::string orbit::http::h2::Http2Session::client_ip_
private

◆ connection_

std::weak_ptr<server::Connection> orbit::http::h2::Http2Session::connection_
private

◆ max_body_size_

size_t orbit::http::h2::Http2Session::max_body_size_
private

◆ proactor_

network::Proactor& orbit::http::h2::Http2Session::proactor_
private

◆ router_

const routing::Router& orbit::http::h2::Http2Session::router_
private

◆ session_

nghttp2_session* orbit::http::h2::Http2Session::session_ {nullptr}
private

◆ session_mutex_

std::mutex orbit::http::h2::Http2Session::session_mutex_
private

◆ streams_

std::unordered_map<int32_t, std::shared_ptr<StreamContext> > orbit::http::h2::Http2Session::streams_
private

◆ thread_pool_

concurrency::ThreadPool& orbit::http::h2::Http2Session::thread_pool_
private

The documentation for this class was generated from the following file: