Seastar
High performance C++ framework for concurrent servers
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 
31 namespace seastar {
32 
33 namespace http {
34 namespace internal {
35 output_stream<char> make_http_chunked_output_stream(output_stream<char>& out);
36 // @param total_len defines the maximum number of bytes to be written.
37 // @param bytes_written after the stream is closed, it is updated with the
38 // actual number of bytes written.
39 output_stream<char> make_http_content_length_output_stream(output_stream<char>& out, size_t total_len, size_t& bytes_written);
40 } // internal namespace
41 } // http namespace
42 
43 namespace httpd {
44 
45 SEASTAR_MODULE_EXPORT_BEGIN
46 
47 class parameters {
48  std::unordered_map<sstring, sstring> params;
49 public:
50  const sstring& path(const sstring& key) const {
51  return params.at(key);
52  }
53 
54  sstring operator[](const sstring& key) const {
55  return params.at(key).substr(1);
56  }
57 
58  const sstring& at(const sstring& key) const {
59  return path(key);
60  }
61 
62  bool exists(const sstring& key) const {
63  return params.find(key) != params.end();
64  }
65 
66  void set(const sstring& key, const sstring& value) {
67  params[key] = value;
68  }
69 
70  void clear() {
71  params.clear();
72  }
73 
74 };
75 
76 enum operation_type {
77  GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT, NUM_OPERATION
78 };
79 
85 operation_type str2type(const sstring& type);
86 
92 sstring type2str(operation_type type);
93 
94 }
95 
96 SEASTAR_MODULE_EXPORT_END
97 }
Definition: common.hh:47
Seastar API namespace.
Definition: abort_on_ebadf.hh:26