Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
file_handler.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright 2015 Cloudius Systems
20 */
21
22#pragma once
23
24#include <seastar/http/handlers.hh>
25#include <seastar/core/iostream.hh>
26#include <seastar/util/modules.hh>
27
28namespace seastar {
29
30namespace httpd {
31
32SEASTAR_MODULE_EXPORT_BEGIN
45public:
52 virtual output_stream<char> transform(std::unique_ptr<http::request> req,
53 const sstring& extension, output_stream<char>&& s) = 0;
54 file_transformer() = default;
56 virtual ~file_transformer() = default;
57};
58
67public:
69 : transformer(p) {
70
71 }
72
74
81 transformer = t;
82 return this;
83 }
84
91 bool redirect_if_needed(const http::request& req, http::reply& rep) const;
92
98 static sstring get_extension(const sstring& file);
99
100protected:
101
109 std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep);
110 file_transformer* transformer;
111
112 output_stream<char> get_stream(std::unique_ptr<http::request> req,
113 const sstring& extension, output_stream<char>&& s);
114};
115
126public:
127
135 explicit directory_handler(const sstring& doc_root,
136 file_transformer* transformer = nullptr);
137
139 std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) override;
140
141private:
142 sstring doc_root;
143};
144
151public:
152
159 explicit file_handler(const sstring& file, file_transformer* transformer =
160 nullptr, bool force_path = true)
161 : file_interaction_handler(transformer), file(file), force_path(
162 force_path) {
163 }
164
166 std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) override;
167
168private:
169 sstring file;
170 bool force_path;
171};
172
173SEASTAR_MODULE_EXPORT_END
174}
175
176}
Definition: file.hh:177
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Definition: file_handler.hh:125
future< std::unique_ptr< http::reply > > handle(const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep) override
directory_handler(const sstring &doc_root, file_transformer *transformer=nullptr)
Definition: file_handler.hh:150
future< std::unique_ptr< http::reply > > handle(const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep) override
file_handler(const sstring &file, file_transformer *transformer=nullptr, bool force_path=true)
Definition: file_handler.hh:159
Definition: file_handler.hh:66
static sstring get_extension(const sstring &file)
file_interaction_handler * set_transformer(file_transformer *t)
Definition: file_handler.hh:80
future< std::unique_ptr< http::reply > > read(sstring file, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep)
bool redirect_if_needed(const http::request &req, http::reply &rep) const
Definition: file_handler.hh:44
virtual output_stream< char > transform(std::unique_ptr< http::request > req, const sstring &extension, output_stream< char > &&s)=0
Definition: handlers.hh:42
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: reply.hh:61
Definition: request.hh:52