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::file_handler Class Reference

Detailed Description

The file handler get a path to a file on the disk in the constructor. it will always return the content of the file.

#include <seastar/http/file_handler.hh>

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

Public Member Functions

 file_handler (const sstring &file, file_transformer *transformer=nullptr, bool force_path=true)
 
future< std::unique_ptr< http::reply > > handle (const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep) override
 
file_interaction_handlerset_transformer (file_transformer *t)
 
bool redirect_if_needed (const http::request &req, http::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< http::reply > > read (sstring file, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep)
 
output_stream< char > get_stream (std::unique_ptr< http::request > req, const sstring &extension, output_stream< char > &&s)
 

Protected Attributes

file_transformertransformer
 

Constructor & Destructor Documentation

◆ file_handler()

seastar::httpd::file_handler::file_handler ( const sstring &  file,
file_transformer transformer = nullptr,
bool  force_path = true 
)
inlineexplicit

The file handler map a file to a url

Parameters
filethe full path to the file on the disk
transformeran optional file transformer
force_pathcheck if redirect is needed upon handle

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<http::reply> > seastar::httpd::file_handler::handle ( const sstring &  path,
std::unique_ptr< http::request req,
std::unique_ptr< http::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<http::reply> > seastar::httpd::file_interaction_handler::read ( sstring  file,
std::unique_ptr< http::request req,
std::unique_ptr< http::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 http::request req,
http::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: