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.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * Copyright 2015 Cloudius Systems
26 // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
33 #include <seastar/core/sstring.hh>
37 #include <seastar/http/common.hh>
45 * A request received from a client.
50 other, multipart, app_x_www_urlencoded,
53 struct case_insensitive_cmp {
54 bool operator()(const sstring& s1, const sstring& s2) const {
55 return std::equal(s1.begin(), s1.end(), s2.begin(), s2.end(),
56 [](char a, char b) { return ::tolower(a) == ::tolower(b); });
60 struct case_insensitive_hash {
61 size_t operator()(sstring s) const {
62 std::transform(s.begin(), s.end(), s.begin(), ::tolower);
63 return std::hash<sstring>()(s);
70 int http_version_major;
71 int http_version_minor;
72 ctclass content_type_class;
73 size_t content_length = 0;
74 std::unordered_map<sstring, sstring, case_insensitive_hash, case_insensitive_cmp> _headers;
75 std::unordered_map<sstring, sstring> query_parameters;
76 connection* connection_ptr;
79 sstring protocol_name = "http";
82 * Search for the first header of a given name
83 * @param name the header name
84 * @return a pointer to the header value, if it exists or empty string
86 sstring get_header(const sstring& name) const {
87 auto res = _headers.find(name);
88 if (res == _headers.end()) {
95 * Search for the first header of a given name
96 * @param name the header name
97 * @return a pointer to the header value, if it exists or empty string
99 sstring get_query_param(const sstring& name) const {
100 auto res = query_parameters.find(name);
101 if (res == query_parameters.end()) {
108 * Get the request protocol name. Can be either "http" or "https".
110 sstring get_protocol_name() const {
111 return protocol_name;
115 * Get the request url.
116 * @return the request url
118 sstring get_url() const {
119 return get_protocol_name() + "://" + get_header("Host") + _url;
122 bool is_multi_part() const {
123 return content_type_class == ctclass::multipart;
126 bool is_form_post() const {
127 return content_type_class == ctclass::app_x_www_urlencoded;