-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPResponse.cpp
More file actions
76 lines (61 loc) · 1.66 KB
/
HTTPResponse.cpp
File metadata and controls
76 lines (61 loc) · 1.66 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
#include "HTTPResponse.h"
HTTPResponse::HTTPResponse() {
}
HTTPResponse::HTTPResponse(const std::string _header_file_path,
const std::string _body_file_path,
CacheType _cache_type) {
header_file_path = _header_file_path;
body_file_path = _body_file_path;
cache_type = _cache_type;
}
HTTPResponse::~HTTPResponse() {
}
std::string HTTPResponse::ReadFileToString(std::string _file_path) {
std::string _content;
std::ifstream _stream;
_stream.open(_file_path.c_str());
if(_stream.is_open()) {
char _buffer[0xFF] = {NULL,};
while(_stream.good()) {
_stream.read(_buffer, 0xFF - 1);
_content.append(_buffer);
memset(_buffer, NULL, 0xFF);
}
_content.append(_buffer);
_stream.close();
}
return _content;
}
const std::string HTTPResponse::GetBodyContent() {
return ReadFileToString(body_file_path);
}
const std::string HTTPResponse::GetHeaderContent() {
return ReadFileToString(header_file_path);
}
const std::string HTTPResponse::SearchHeaderField(const std::string _field_name) {
std::string _field;
std::string _header = GetHeaderContent();
char _buffer = NULL;
int _start = _header.find(_field_name.c_str());
if(_start < 0)
return _field;
int _end = _header.length();
int _i = _start + _field_name.length() + std::string(": ").length();
while(_i > 0 && _i < _end) {
_buffer = _header.at(_i);
if((_buffer == '\n') ||
(_buffer == '\r') ||
(_buffer == '\0') ||
(_buffer == ';')) {
break;
} else {
_field.append(sizeof(char), _buffer);
}
_i++;
}
return _field;
}
const HTTPResponseHeaderField HTTPResponse::ParseHeader() {
HTTPResponseHeaderField _field(header_file_path);
return _field;
}