SNode.C
Loading...
Searching...
No Matches
Chunked.h
Go to the documentation of this file.
1/*
2 * snode.c - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef WEB_HTTP_DECODER_CHUNK_H
21#define WEB_HTTP_DECODER_CHUNK_H
22
23#include "web/http/ContentDecoder.h" // IWYU pragma: export
24
25namespace core::socket::stream {
26 class SocketContext;
27}
28
29#ifndef DOXYGEN_SHOULD_SKIP_THIS
30
31#include <cstddef>
32#include <string>
33#include <vector>
34
35#endif // DOXYGEN_SHOULD_SKIP_THIS
36
37namespace web::http::decoder {
38
39 class Chunked : public web::http::ContentDecoder { // Extends decoder
40 private:
41 class Chunk {
42 public:
43 Chunk() = default;
44
45 Chunk(const Chunk&) = delete;
46 Chunk(Chunk&&) noexcept = default;
47
48 Chunk& operator=(const Chunk&) = delete;
49 Chunk& operator=(Chunk&&) noexcept = default;
50
51 ~Chunk();
52
53 inline std::size_t read(const core::socket::stream::SocketContext* socketContext);
54
55 bool isError() const;
56 bool isComplete() const;
57
58 std::vector<char>::iterator begin();
59 std::vector<char>::iterator end();
60
61 std::size_t size();
62
63 private:
65
66 std::string chunkLenTotalS;
67 std::size_t chunkLenTotal = 0;
68 std::size_t chunkLenRead = 0;
69
70 int state = 0;
71
72 bool CR = false;
73 bool LF = false;
74
75 bool error = false;
76 bool completed = false;
77 };
78
79 public:
80 explicit Chunked(const core::socket::stream::SocketContext* socketContext);
81
82 Chunked(const Chunked&) = delete;
83 Chunked(Chunked&&) noexcept = default;
84
85 Chunked& operator=(const Chunked&) = delete;
86 Chunked& operator=(Chunked&&) noexcept = default;
87
88 private:
89 std::size_t read() override;
90
91 const core::socket::stream::SocketContext* socketContext;
92
94
95 int state = 0;
96 };
97
98} // namespace web::http::decoder
99
100#endif // WEB_HTTP_DECODER_CHUNK_H
std::size_t readFromPeer(char *chunk, std::size_t chunklen) const final
std::size_t read(const core::socket::stream::SocketContext *socketContext)
Definition Chunked.cpp:74
Chunk & operator=(Chunk &&) noexcept=default
Chunk & operator=(const Chunk &)=delete
Chunk(Chunk &&) noexcept=default
std::vector< char >::iterator begin()
Definition Chunked.cpp:193
std::vector< char > chunk
Definition Chunked.h:64
std::vector< char >::iterator end()
Definition Chunked.cpp:197
Chunked(const core::socket::stream::SocketContext *socketContext)
Definition Chunked.cpp:32
Chunked(Chunked &&) noexcept=default
const core::socket::stream::SocketContext * socketContext
Definition Chunked.h:91
std::size_t read() override
Definition Chunked.cpp:36
Chunked & operator=(Chunked &&) noexcept=default
Chunked(const Chunked &)=delete
Chunked & operator=(const Chunked &)=delete