Sese Framework  3.0.0
A cross-platform framework
Loading...
Searching...
No Matches
HttpClient.h
Go to the documentation of this file.
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
19
20#pragma once
21
26
27#include <functional>
28
29namespace sese::net::http {
32public:
33 using WriteCallback = std::function<int64_t(const void *, size_t)>;
34 using ReadCallback = std::function<int64_t(void *, size_t)>;
35 using Ptr = std::unique_ptr<HttpClient>;
36
41 static Ptr create(const std::string &url, const std::string &proxy = "");
42
44
47 bool request() const;
48
51 int getLastError() const;
52
55 std::string getLastErrorString() const;
56
57 int64_t read(void *buf, size_t len) const;
58
59 int64_t write(const void *buf, size_t len) const;
60
63 Request::Ptr &getRequest() const;
64
68
72 void setReadData(io::PeekableStream *read_data, size_t expect_total) const;
73
76 void setWriteData(io::OutputStream *write_data) const;
77
81 void setReadCallback(const ReadCallback &read_callback, size_t expect_total) const;
82
85 void setWriteCallback(const WriteCallback &write_callback) const;
86
87private:
88 HttpClient() = default;
89
90 class Impl;
91 class SSLImpl;
92 std::unique_ptr<Impl> impl;
93};
94} // namespace sese::net::http