userver: userver/server/handlers/http_handler_static.hpp Source File
Loading...
Searching...
No Matches
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/// ## HttpHandlerStatic 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 {
42public:
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, const components::ComponentContext& context);
50
51 std::string HandleRequestThrow(const http::HttpRequest& request, request::RequestContext&) const override;
52
53 static yaml_config::Schema GetStaticConfigSchema();
54
55private:
56 dynamic_config::Source config_;
57 const fs::FsCacheClient& storage_;
58};
59
60} // namespace server::handlers
61
62USERVER_NAMESPACE_END