Seastar
High performance C++ framework for concurrent servers
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
seastar::httpd::directory_handler Class Reference

Detailed Description

The directory handler get a disk path in the constructor. and expect a path parameter in the handle method. it would concatenate the two and return the file e.g. if the path is /usr/mgmt/public in the path parameter is index.html handle will return the content of /usr/mgmt/public/index.html

#include <seastar/http/file_handler.hh>

Inheritance diagram for seastar::httpd::directory_handler:
seastar::httpd::file_interaction_handler seastar::httpd::handler_base

Public Member Functions

 directory_handler (const sstring &doc_root, file_transformer *transformer=nullptr)
 
future< std::unique_ptr< reply > > handle (const sstring &path, std::unique_ptr< request > req, std::unique_ptr< reply > rep) override
 
file_interaction_handlerset_transformer (file_transformer *t)
 
bool redirect_if_needed (const request &req, reply &rep) const
 
handler_basemandatory (const sstring &param)
 

Static Public Member Functions

static sstring get_extension (const sstring &file)
 

Public Attributes

std::vector< sstring > _mandatory_param
 

Protected Member Functions

future< std::unique_ptr< reply > > read (sstring file, std::unique_ptr< request > req, std::unique_ptr< reply > rep)
 
output_stream< char > get_stream (std::unique_ptr< request > req, const sstring &extension, output_stream< char > &&s)
 

Protected Attributes

file_transformertransformer
 

Constructor & Destructor Documentation

◆ directory_handler()

seastar::httpd::directory_handler::directory_handler ( const sstring &  doc_root,
file_transformer transformer = nullptr 
)
explicit

The directory handler map a base path and a path parameter to a file

Parameters
doc_rootthe root directory to search the file from.
transformeran optional file transformer For example if the root is '/usr/mgmt/public' and the path parameter will be '/css/style.css' the file wil be /usr/mgmt/public/css/style.css'

Member Function Documentation

◆ get_extension()

static sstring seastar::httpd::file_interaction_handler::get_extension ( const sstring &  file)
staticinherited

A helper method that returns the file extension.

Parameters
filethe file to check
Returns
the file extension

◆ handle()

future<std::unique_ptr<reply> > seastar::httpd::directory_handler::handle ( const sstring &  path,
std::unique_ptr< request req,
std::unique_ptr< reply rep 
)
overridevirtual

All handlers should implement this method. It fill the reply according to the request.

Parameters
paththe url path used in this call
reqthe original request
repthe reply

Implements seastar::httpd::handler_base.

◆ mandatory()

handler_base& seastar::httpd::handler_base::mandatory ( const sstring &  param)
inlineinherited

Add a mandatory parameter

Parameters
parama parameter name
Returns
a reference to the handler

◆ read()

future<std::unique_ptr<reply> > seastar::httpd::file_interaction_handler::read ( sstring  file,
std::unique_ptr< request req,
std::unique_ptr< reply rep 
)
protectedinherited

read a file from the disk and return it in the replay.

Parameters
filethe full path to a file on the disk
reqthe reuest
repthe reply

◆ redirect_if_needed()

bool seastar::httpd::file_interaction_handler::redirect_if_needed ( const request req,
reply rep 
) const
inherited

if the url ends without a slash redirect

Parameters
reqthe request
repthe reply
Returns
true on redirect

◆ set_transformer()

file_interaction_handler* seastar::httpd::file_interaction_handler::set_transformer ( file_transformer t)
inlineinherited

Allows setting a transformer to be used with the files returned.

Parameters
tthe file transformer to use
Returns
this

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