Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
HttpUtil.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
27#include <sese/io/Stream.h>
28
29namespace sese::net::http {
30
32class HttpUtil {
33public:
36
45 static bool recvRequest(InputStream *source, RequestHeader *request) noexcept;
54 static bool sendRequest(OutputStream *dest, RequestHeader *request) noexcept;
63 static bool recvResponse(InputStream *source, ResponseHeader *response) noexcept;
72 static bool sendResponse(OutputStream *dest, ResponseHeader *response) noexcept;
73
74 static Cookie::Ptr parseFromSetCookie(const std::string &text) noexcept;
75
76 static CookieMap::Ptr parseFromCookie(const std::string &text) noexcept;
77
79 static std::map<std::string, std::string> content_type_map;
80
81private:
82 static bool getLine(InputStream *source, text::StringBuilder &builder) noexcept;
83
84 inline static bool recvHeader(InputStream *source, text::StringBuilder &builder, Header *header, bool is_resp = false) noexcept;
85 inline static bool sendHeader(OutputStream *dest, Header *header, bool is_resp = false) noexcept;
86
87 inline static bool sendSetCookie(OutputStream *dest, const CookieMap::Ptr &cookies) noexcept;
88 inline static bool sendCookie(OutputStream *dest, const CookieMap::Ptr &cookies) noexcept;
89};
90} // namespace sese::net::http