Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
common.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#ifndef SEASTAR_MODULE
25#include <unordered_map>
26#endif
27
28#include <seastar/core/sstring.hh>
29#include <seastar/core/iostream.hh>
30#include <seastar/http/url.hh>
31
32namespace seastar {
33
34namespace http {
35namespace internal {
36output_stream<char> make_http_chunked_output_stream(output_stream<char>& out);
37// @param total_len defines the maximum number of bytes to be written.
38// @param bytes_written after the stream is closed, it is updated with the
39// actual number of bytes written.
40output_stream<char> make_http_content_length_output_stream(output_stream<char>& out, size_t total_len, size_t& bytes_written);
41} // internal namespace
42} // http namespace
43
44namespace httpd {
45
46SEASTAR_MODULE_EXPORT_BEGIN
47
49 // Note: the path matcher adds parameters with the '/' prefix into the params map (eg. "/param1"), and some getters
50 // remove this '/' to return just the path parameter value
51 std::unordered_map<sstring, sstring> params;
52public:
53 const sstring& path(const sstring& key) const {
54 return params.at(key);
55 }
56
57 [[deprecated("Use request::get_path_param() instead.")]]
58 sstring operator[](const sstring& key) const {
59 return params.at(key).substr(1);
60 }
61
62 const sstring& at(const sstring& key) const {
63 return path(key);
64 }
65
66 sstring get_decoded_param(const sstring& key) const {
67 auto res = params.find(key);
68 if (res == params.end()) {
69 return "";
70 }
71 auto raw_path_param = res->second.substr(1);
72 auto decoded_path_param = sstring{};
73 auto ok = seastar::http::internal::path_decode(raw_path_param, decoded_path_param);
74 if (!ok) {
75 return "";
76 }
77 return decoded_path_param;
78 }
79
80 bool exists(const sstring& key) const {
81 return params.find(key) != params.end();
82 }
83
84 void set(const sstring& key, const sstring& value) {
85 params[key] = value;
86 }
87
88 void clear() {
89 params.clear();
90 }
91
92};
93
94enum operation_type {
95 GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT, PATCH, NUM_OPERATION
96};
97
103operation_type str2type(const sstring& type);
104
110sstring type2str(operation_type type);
111
112}
113
114SEASTAR_MODULE_EXPORT_END
115}
Definition: common.hh:48
Seastar API namespace.
Definition: abort_on_ebadf.hh:26