-
Notifications
You must be signed in to change notification settings - Fork 21
/
multipart_parser.h
55 lines (48 loc) · 1.55 KB
/
multipart_parser.h
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
/*********************************************************************************
* File Name : gen_multipart.h
* Created By : Ye Yangang
* Creation Date : [2017-02-20 16:50]
* Last Modified : [AUTO_UPDATE_BEFORE_SAVE]
* Description : Generate multipart/form-data POST body
**********************************************************************************/
#ifndef GEN_MULTIPART_H_
#define GEN_MULTIPART_H_
#include <vector>
#include <string>
#include <tuple>
namespace web{
namespace http{
class MultipartParser
{
public:
MultipartParser();
inline const std::string &body_content()
{
return body_content_;
}
inline const std::string &boundary()
{
return boundary_;
}
inline void AddParameter(const std::string &name, const std::string &value)
{
params_.push_back(std::move(std::pair<std::string, std::string>(name, value)));
}
inline void AddFile(const std::string &name, const std::string &value)
{
files_.push_back(std::move(std::pair<std::string, std::string>(name, value)));
}
const std::string &GenBodyContent();
private:
void _get_file_name_type(const std::string &file_path, std::string *filenae, std::string *content_type);
private:
static const std::string boundary_prefix_;
static const std::string rand_chars_;
std::string boundary_;
std::string body_content_;
std::vector<std::pair<std::string, std::string> > params_;
std::vector<std::pair<std::string, std::string> > files_;
};
} //namespace web::http
} //namespace web
#endif