Seastar
High performance C++ framework for concurrent servers
|
A base class for handlers that interact with files. directory and file handlers both share some common logic with regards to file handling. they both needs to read a file from the disk, optionally transform it, and return the result or page not found on error
#include <seastar/http/file_handler.hh>
Public Member Functions | |
file_interaction_handler (file_transformer *p=nullptr) | |
file_interaction_handler * | set_transformer (file_transformer *t) |
bool | redirect_if_needed (const http::request &req, http::reply &rep) const |
virtual future< std::unique_ptr< http::reply > > | handle (const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep)=0 |
handler_base & | mandatory (const sstring ¶m) |
void | verify_mandatory_params (const http::request &req) const |
Static Public Member Functions | |
static sstring | get_extension (const sstring &file) |
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_transformer * | transformer |
|
static |
A helper method that returns the file extension.
file | the file to check |
|
pure virtualinherited |
All handlers should implement this method. It fill the reply according to the request.
path | the url path used in this call |
req | the original request |
rep | the reply |
Implemented in seastar::httpd::api_registry, seastar::httpd::api_registry_20, seastar::httpd::directory_handler, seastar::httpd::file_handler, and seastar::httpd::function_handler.
|
inlineinherited |
Add a mandatory parameter
param | a parameter name |
|
protected |
read a file from the disk and return it in the replay.
file | the full path to a file on the disk |
req | the reuest |
rep | the reply |
bool seastar::httpd::file_interaction_handler::redirect_if_needed | ( | const http::request & | req, |
http::reply & | rep | ||
) | const |
if the url ends without a slash redirect
req | the request |
rep | the reply |
|
inline |
Allows setting a transformer to be used with the files returned.
t | the file transformer to use |
|
inlineinherited |
Check if all mandatory parameters exist in the request. if any param does not exist, the function would throw a missing_param_exception
params | req the http request |