Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Header.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
22#pragma once
23
26#include <sese/Util.h>
27
28#ifdef _WIN32
29#pragma warning(disable : 4251)
30#endif
31
32namespace sese::net::http {
33
35enum class HttpVersion {
39};
40
44class Header {
45public:
46 using Ptr = std::unique_ptr<Header>;
47 using KeyValueType = std::pair<std::string, std::string>;
48
49 explicit Header() = default;
50 Header(const std::initializer_list<KeyValueType> &initializer_list) noexcept;
51 virtual ~Header() = default;
52
53 void set(const std::string &key, const std::string &value) noexcept;
54 const std::string &get(const std::string &key, const std::string &default_value) noexcept;
55#if SESE_CXX_STANDARD > 201700L
56 std::string_view getView(const std::string &key, const std::string &default_value) noexcept;
57#endif
58 std::map<std::string, std::string>::iterator begin() noexcept { return headers.begin(); }
59 std::map<std::string, std::string>::iterator end() noexcept { return headers.end(); }
60 auto find(const std::string &key) noexcept { return headers.find(key); }
61
62 void clear() { headers.clear(); }
63 [[nodiscard]] bool empty() const { return headers.empty(); }
64 [[nodiscard]] size_t size() const { return headers.size(); }
65
69 bool exist(const std::string &key) { return headers.find(key) != headers.end(); }
74 const std::string &get(const std::string &key) { return headers.at(key); }
75
78 [[nodiscard]] const CookieMap::Ptr &getCookies() const;
82
86 [[nodiscard]] Cookie::Ptr getCookie(const std::string &name) const;
89 void setCookie(const Cookie::Ptr &cookie);
90
91protected:
94};
95} // namespace sese::net::http