Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
matchrules.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/http/matcher.hh>
26#include <seastar/http/common.hh>
27
28#include <seastar/core/sstring.hh>
29#include <vector>
30
31namespace seastar {
32
33namespace httpd {
34
43public:
48 for (auto m : _match_list) {
49 delete m;
50 }
51 delete _handler;
52 }
53
58 explicit match_rule(handler_base* handler)
59 : _handler(handler) {
60 }
61
69 handler_base* get(const sstring& url, parameters& params) {
70 size_t ind = 0;
71 if (_match_list.empty()) {
72 return _handler;
73 }
74 for (unsigned int i = 0; i < _match_list.size(); i++) {
75 ind = _match_list.at(i)->match(url, ind, params);
76 if (ind == sstring::npos) {
77 return nullptr;
78 }
79 }
80 return (ind + 1 >= url.length()) ? _handler : nullptr;
81 }
82
89 _match_list.push_back(match);
90 return *this;
91 }
92
98 match_rule& add_str(const sstring& str) {
99 add_matcher(new str_matcher(str));
100 return *this;
101 }
102
110 match_rule& add_param(const sstring& str, bool fullpath = false) {
111 add_matcher(new param_matcher(str, fullpath));
112 return *this;
113 }
114
115private:
116 std::vector<matcher*> _match_list;
117 handler_base* _handler;
118};
119
120}
121
122}
Definition: handlers.hh:42
Definition: matchrules.hh:42
handler_base * get(const sstring &url, parameters &params)
Definition: matchrules.hh:69
~match_rule()
Definition: matchrules.hh:47
match_rule & add_matcher(matcher *match)
Definition: matchrules.hh:88
match_rule & add_param(const sstring &str, bool fullpath=false)
Definition: matchrules.hh:110
match_rule(handler_base *handler)
Definition: matchrules.hh:58
match_rule & add_str(const sstring &str)
Definition: matchrules.hh:98
Definition: matcher.hh:36
Definition: matcher.hh:65
Definition: common.hh:48
Definition: matcher.hh:92
Definition: routes.hh:43
Seastar API namespace.
Definition: abort_on_ebadf.hh:26