Boost C++ Libraries

PrevUpHomeNext

Struct template with_session_handler

boost::taar::handler::with_session_handler — Handler decorator that binds a keyed context from a context_store.

Synopsis

// In header: <boost/taar/handler/with_session.hpp>

template<typename Store, typename KeyExtractor, typename Inner> 
struct with_session_handler {
  // types
  typedef unspecified                  request_type;
  typedef Store                        store_type;  
  typedef typename Store::context_type context_type;
  typedef Inner                        inner_type;    // The wrapped handler, for documentation generators that introspect it. 

  // public member functions
  template<typename Contexts> 
    auto operator()(Contexts const &, request_type const &, 
                    matcher::context const &);
  auto path_arg_names() const;
  auto params() const;

  // public data members
  static constexpr bool context_aware;
  Store * store_;
  KeyExtractor key_;
  session_policy policy_;
  Inner inner_;
};

Description

Produced by with_session. On each request it extracts the key with the configured extractor, looks the entry up in the store, applies the policy when the key is absent or unknown, acquires the entry's lock, and invokes the inner handler with the keyed context added to the contexts in scope. When a key was minted the extractor writes it into the response.

The inner handler may produce a typed boost::beast::http::response (the usual case for rest and raw handlers) or a stream: a chunked_response<T> or async_generator<T>, directly or through an awaitable. A stream is re-emitted as chunked_response<T> with the minted key's header added. The entry's lock is held only while the inner handler runs, that is until it has produced the stream; the stream body then runs unlocked, so a long-lived stream does not block the client's other requests. A streaming handler that keeps using the keyed context must therefore synchronise that access itself (an async_channel in the context is the usual shape). message_generator results are not supported under with_session.

If the inner handler throws, the exception propagates to the session's soft-error handler as usual. A key minted on that request is not communicated to the client; the entry is left for the sweeper.

with_session_handler public member functions

  1. template<typename Contexts> 
      auto operator()(Contexts const & ctxs, request_type const & request, 
                      matcher::context const & mctx);
  2. auto path_arg_names() const;
  3. auto params() const;

PrevUpHomeNext