]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/http/request.hh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / include / seastar / http / request.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 //
23 // request.hpp
24 // ~~~~~~~~~~~
25 //
26 // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
27 //
28 // Distributed under the Boost Software License, Version 1.0. (See accompanying
29 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
30 //
31 #pragma once
32
33 #include <seastar/core/sstring.hh>
34 #include <string>
35 #include <vector>
36 #include <strings.h>
37 #include <seastar/http/common.hh>
38
39 namespace seastar {
40
41 namespace httpd {
42 class connection;
43
44 /**
45 * A request received from a client.
46 */
47 struct request {
48 enum class ctclass
49 : char {
50 other, multipart, app_x_www_urlencoded,
51 };
52
53 sstring _method;
54 sstring _url;
55 sstring _version;
56 int http_version_major;
57 int http_version_minor;
58 ctclass content_type_class;
59 size_t content_length = 0;
60 std::unordered_map<sstring, sstring> _headers;
61 std::unordered_map<sstring, sstring> query_parameters;
62 connection* connection_ptr;
63 parameters param;
64 sstring content;
65 sstring protocol_name = "http";
66
67 /**
68 * Search for the first header of a given name
69 * @param name the header name
70 * @return a pointer to the header value, if it exists or empty string
71 */
72 sstring get_header(const sstring& name) const {
73 auto res = _headers.find(name);
74 if (res == _headers.end()) {
75 return "";
76 }
77 return res->second;
78 }
79
80 /**
81 * Search for the first header of a given name
82 * @param name the header name
83 * @return a pointer to the header value, if it exists or empty string
84 */
85 sstring get_query_param(const sstring& name) const {
86 auto res = query_parameters.find(name);
87 if (res == query_parameters.end()) {
88 return "";
89 }
90 return res->second;
91 }
92
93 /**
94 * Get the request protocol name. Can be either "http" or "https".
95 */
96 sstring get_protocol_name() const {
97 return protocol_name;
98 }
99
100 /**
101 * Get the request url.
102 * @return the request url
103 */
104 sstring get_url() const {
105 return get_protocol_name() + "://" + get_header("Host") + _url;
106 }
107
108 bool is_multi_part() const {
109 return content_type_class == ctclass::multipart;
110 }
111
112 bool is_form_post() const {
113 return content_type_class == ctclass::app_x_www_urlencoded;
114 }
115
116 };
117
118 } // namespace httpd
119
120 }