Sese Framework
2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
Requestable.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
22
#include <
sese/net/http/Request.h
>
23
#include <
sese/net/http/Response.h
>
24
#include <
sese/io/InputStream.h
>
25
#include <
sese/io/PeekableStream.h
>
26
#include <
sese/io/OutputStream.h
>
27
28
#include <functional>
29
30
namespace
sese::net::http
{
32
class
Requestable
:
public
io::InputStream
,
public
io::OutputStream
{
33
public
:
34
using
WriteCallback
= std::function<int64_t(
const
void
*,
size_t
)>;
35
using
ReadCallback
= std::function<int64_t(
void
*,
size_t
)>;
36
37
~Requestable
()
override
=
default
;
38
41
virtual
bool
request
() = 0;
42
45
virtual
int
getLastError
() = 0;
46
49
virtual
std::string
getLastErrorString
() = 0;
50
51
int64_t
read
(
void
*buf,
size_t
len)
override
= 0;
52
53
int64_t
write
(
const
void
*buf,
size_t
len)
override
= 0;
54
57
Request::Ptr
&
getRequest
() {
return
req
; }
58
61
Response::Ptr
&
getResponse
() {
return
resp
; }
62
66
void
setReadData
(
io::PeekableStream
*
read_data
,
size_t
expect_total
) {
67
this->read_data =
read_data
;
68
this->expect_total =
expect_total
;
69
}
70
73
void
setWriteData
(
io::OutputStream
*
write_data
) {
74
this->write_data =
write_data
;
75
}
76
80
void
setReadCallback
(
const
ReadCallback
&
read_callback
,
size_t
expect_total
) {
81
this->read_callback =
read_callback
;
82
this->expect_total =
expect_total
;
83
}
84
87
void
setWriteCallback
(
const
WriteCallback
&
write_callback
) {
88
this->write_callback =
write_callback
;
89
}
90
92
void
reset
() {
93
expect_total
= 0;
94
read_data
= &
req
->getBody();
95
write_data
= &
resp
->getBody();
96
read_callback
=
nullptr
;
97
write_callback
=
nullptr
;
98
}
99
100
protected
:
101
Request::Ptr
req
=
nullptr
;
102
Response::Ptr
resp
=
nullptr
;
103
104
size_t
expect_total
= 0;
105
106
io::PeekableStream
*
read_data
=
nullptr
;
107
io::OutputStream
*
write_data
=
nullptr
;
108
109
WriteCallback
write_callback
;
110
ReadCallback
read_callback
;
111
};
112
}
// namespace sese::net::http
sese
net
http
Requestable.h
Generated on Tue Jan 7 2025 15:49:06 for Sese Framework by
1.11.0