-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResponse.cpp
105 lines (86 loc) · 2.51 KB
/
Response.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Response.h"
using namespace OTF;
void Response::writeStatus(uint16_t statusCode, const String &statusMessage) {
if (responseStatus > CREATED) {
valid = false;
return;
}
responseStatus = STATUS_WRITTEN;
bprintf(F("HTTP/1.1 %d %s\r\n"), statusCode, statusMessage.c_str());
}
void Response::writeStatus(uint16_t statusCode, const __FlashStringHelper *const statusMessage) {
if (responseStatus > CREATED) {
valid = false;
return;
}
responseStatus = STATUS_WRITTEN;
bprintf(F("HTTP/1.1 %d %s\r\n"), statusCode, statusMessage);
}
void Response::writeStatus(uint16_t statusCode) {
if (responseStatus > CREATED) {
valid = false;
return;
}
responseStatus = STATUS_WRITTEN;
writeStatus(statusCode, F("No message"));
}
/*void Response::writeHeader(char *const name, char *const value) {
if (responseStatus < STATUS_WRITTEN || responseStatus > HEADERS_WRITTEN) {
valid = false;
return;
}
responseStatus = HEADERS_WRITTEN;
bprintf(F("%s: %s\r\n"), name, value);
}
void Response::writeHeader(const __FlashStringHelper *const name, char *const value) {
if (responseStatus < STATUS_WRITTEN || responseStatus > HEADERS_WRITTEN) {
valid = false;
return;
}
responseStatus = HEADERS_WRITTEN;
bprintf(F("%s: %s\r\n"), name, value);
}*/
void Response::writeHeader(const __FlashStringHelper *const name, int value) {
if (responseStatus < STATUS_WRITTEN || responseStatus > HEADERS_WRITTEN) {
valid = false;
return;
}
responseStatus = HEADERS_WRITTEN;
bprintf(F("%s: %d\r\n"), name, value);
}
void Response::writeHeader(const __FlashStringHelper *const name, const __FlashStringHelper *const value) {
if (responseStatus < STATUS_WRITTEN || responseStatus > HEADERS_WRITTEN) {
valid = false;
return;
}
responseStatus = HEADERS_WRITTEN;
bprintf(F("%s: %s\r\n"), name, value);
}
void Response::writeBodyChunk(char *const format, ...) {
if (responseStatus < STATUS_WRITTEN) {
valid = false;
return;
}
if (responseStatus != BODY_WRITTEN) {
bprintf((char *) "\r\n");
responseStatus = BODY_WRITTEN;
}
va_list args;
va_start(args, format);
bprintf(format, args);
va_end(args);
}
void Response::writeBodyChunk(const __FlashStringHelper *const format, ...) {
if (responseStatus < STATUS_WRITTEN) {
valid = false;
return;
}
if (responseStatus != BODY_WRITTEN) {
bprintf((char *) "\r\n");
responseStatus = BODY_WRITTEN;
}
va_list args;
va_start(args, format);
bprintf(format, args);
va_end(args);
}