-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResponse.h
executable file
·63 lines (45 loc) · 2.11 KB
/
Response.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
56
57
58
59
60
61
62
63
#ifndef OTF_RESPONSE_H
#define OTF_RESPONSE_H
#include "StringBuilder.h"
#include <Arduino.h>
// The maximum possible size of response messages.
#define RESPONSE_BUFFER_SIZE 18000
namespace OTF {
class Response : public StringBuilder {
friend class OpenThingsFramework;
private:
enum ResponseStatus {
CREATED,
STATUS_WRITTEN,
HEADERS_WRITTEN,
BODY_WRITTEN
};
ResponseStatus responseStatus = CREATED;
Response() : StringBuilder(RESPONSE_BUFFER_SIZE) {}
public:
static const size_t MAX_RESPONSE_LENGTH = RESPONSE_BUFFER_SIZE;
/** Writes the status code/message to the response. This must be called before writing the headers or body. */
void writeStatus(uint16_t statusCode, const String &statusMessage);
/** Writes the status code/message to the response. This must be called before writing the headers or body. */
void writeStatus(uint16_t statusCode, const __FlashStringHelper *const statusMessage);
/** Writes the status code to the response. This must be called before writing the headers or body. */
void writeStatus(uint16_t statusCode);
/** Sets a response header. If called multiple times with the same header name, the header will be specified
* multiple times to create a list. This function must not be called before the status has been written or after
* the body has been written.
*/
//void writeHeader(char *const name, char *const value);
//void writeHeader(const __FlashStringHelper *const name, char *const value);
void writeHeader(const __FlashStringHelper *const name, const __FlashStringHelper *const value);
void writeHeader(const __FlashStringHelper *const name, int value);
/**
* Calls sprintf to write a chunk of data to the response body. This method may only be called after any desired
* headers have been set.
* @param format The format string to pass to sprintf.
* @param ... The format arguments to pass to sprintf.
*/
void writeBodyChunk(char *format, ...);
void writeBodyChunk(const __FlashStringHelper *const format, ...);
};
}// namespace OTF
#endif