userver: userver/server/handlers/http_handler_static.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
http_handler_static.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/http_handler_static.hpp
4/// @brief @copybrief server::handlers::HttpHandlerStatic
5
6#include <userver/components/fs_cache.hpp>
7#include <userver/dynamic_config/source.hpp>
8#include <userver/fs/fs_cache_client.hpp>
9#include <userver/server/handlers/http_handler_base.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace server::handlers {
14
15// clang-format off
16
17/// @ingroup userver_components userver_http_handlers
18///
19/// @brief Handler that returns HTTP 200 if file exist
20/// and returns file data with mapped content/type
21///
22/// ## Dynamic config
23/// * @ref USERVER_FILES_CONTENT_TYPE_MAP
24///
25/// \ref userver_http_handlers "Userver HTTP Handlers".
26///
27/// ## Static options:
28/// Inherits all the options from server::handlers::HttpHandlerBase and adds the
29/// following ones:
30///
31/// Name | Description | Default value
32/// ------------------ | ----------------------------- | -------------
33/// fs-cache-component | Name of the FsCache component | fs-cache-component
34///
35/// ## Example usage:
36///
37/// @snippet samples/static_service/static_service.cpp Static service sample - main
38
39// clang-format on
40
41class HttpHandlerStatic final : public HttpHandlerBase {
42 public:
43 /// @ingroup userver_component_names
44 /// @brief The default name of server::handlers::HttpHandlerStatic
45 static constexpr std::string_view kName = "handler-static";
46
47 using HttpHandlerBase::HttpHandlerBase;
48
49 HttpHandlerStatic(const components::ComponentConfig& config,
50 const components::ComponentContext& context);
51
52 std::string HandleRequestThrow(const http::HttpRequest& request,
53 request::RequestContext&) const override;
54
55 static yaml_config::Schema GetStaticConfigSchema();
56
57 private:
58 dynamic_config::Source config_;
59 const fs::FsCacheClient& storage_;
60};
61
62} // namespace server::handlers
63
64USERVER_NAMESPACE_END