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,
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;
65 sstring protocol_name = "http";
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
72 sstring get_header(const sstring& name) const {
73 auto res = _headers.find(name);
74 if (res == _headers.end()) {
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
85 sstring get_query_param(const sstring& name) const {
86 auto res = query_parameters.find(name);
87 if (res == query_parameters.end()) {
94 * Get the request protocol name. Can be either "http" or "https".
96 sstring get_protocol_name() const {
101 * Get the request url.
102 * @return the request url
104 sstring get_url() const {
105 return get_protocol_name() + "://" + get_header("Host") + _url;
108 bool is_multi_part() const {
109 return content_type_class == ctclass::multipart;
112 bool is_form_post() const {
113 return content_type_class == ctclass::app_x_www_urlencoded;