-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmultipart_form_sink.hpp
More file actions
90 lines (74 loc) · 1.73 KB
/
multipart_form_sink.hpp
File metadata and controls
90 lines (74 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Copyright (c) 2025 Mohammad Nejati
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/http_proto
//
#ifndef BOOST_HTTP_PROTO_MULTIPART_FORM_SINK_HPP
#define BOOST_HTTP_PROTO_MULTIPART_FORM_SINK_HPP
#include <boost/capy/file.hpp>
#include <boost/http_proto/sink.hpp>
#include <boost/optional.hpp>
#include <boost/variant2.hpp>
#include <vector>
namespace boost {
namespace http_proto {
class BOOST_HTTP_PROTO_SYMBOL_VISIBLE multipart_form_sink
: public http_proto::sink
{
public:
struct file_field
{
std::string name;
std::string path;
};
struct text_field
{
std::string data;
};
struct part
{
std::string name;
variant2::variant<text_field, file_field> content;
boost::optional<std::string> content_type;
};
BOOST_HTTP_PROTO_DECL
explicit
multipart_form_sink(
core::string_view boundary);
BOOST_HTTP_PROTO_DECL
boost::span<part const>
parts() const noexcept;
private:
BOOST_HTTP_PROTO_DECL
results
on_write(
buffers::const_buffer b,
bool more) override;
void
parse(
bool match,
core::string_view b,
system::error_code& ec);
enum class state
{
preamble,
post_boundary0,
post_boundary1,
post_boundary2,
header,
content,
finished
};
state state_ = state::preamble;
std::string needle_;
std::string leftover_;
std::string header_;
capy::file file_;
std::vector<part> parts_;
};
} // http_proto
} // boost
#endif