-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathStreamHttpReply.hpp
More file actions
102 lines (83 loc) · 2.99 KB
/
StreamHttpReply.hpp
File metadata and controls
102 lines (83 loc) · 2.99 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
91
92
93
94
95
96
97
98
99
100
101
102
//
//! \file
// ArduinoHttpServer
//
// Created by Sander van Woensel on 23-01-16.
// Copyright (c) 2016 Sander van Woensel. All rights reserved.
//
//! HTTP reply printed to Stream.
#ifndef __ArduinoHttpServer__StreamHttpReply__
#define __ArduinoHttpServer__StreamHttpReply__
#include <Arduino.h>
#include "ArduinoHttpServerDebug.h"
namespace ArduinoHttpServer
{
class Header
{
public:
const char* header;
Header* next;
Header(const char* header);
~Header();
};
//------------------------------------------------------------------------------
// Class Declaration
//------------------------------------------------------------------------------
//! Shared Reply functionality
class AbstractStreamHttpReply
{
public:
virtual void send(const String& data, const String& title);
virtual void addHeader(const char* header);
~AbstractStreamHttpReply();
protected:
AbstractStreamHttpReply(Stream& stream, const String& contentType, const String& code);
virtual Stream& getStream();
virtual const String& getCode();
virtual const String& getContentType();
constexpr static const char* CONTENT_TYPE_TEXT_HTML PROGMEM = "text/html";
constexpr static const char* CONTENT_TYPE_APPLICATION_JSON PROGMEM = "application/json";
private:
Stream& m_stream;
String m_contentType; //!< Needs to be overridden to default when required. Therefore not const.
const String m_code;
Header* headers_head;
Header* headers_tail;
};
//------------------------------------------------------------------------------
// Class Declaration
//------------------------------------------------------------------------------
//! Error reply
class StreamHttpErrorReply: public AbstractStreamHttpReply
{
public:
StreamHttpErrorReply(Stream& stream, const String& contentType, const String& code = "400");
virtual void send(const String& data);
protected:
virtual String getHtmlBody(const String& data);
virtual String getJsonBody(const String& data);
};
//------------------------------------------------------------------------------
// Class Declaration
//------------------------------------------------------------------------------
//! Authenticate reply
#ifndef ARDUINO_HTTP_SERVER_NO_BASIC_AUTH
class StreamHttpAuthenticateReply: public AbstractStreamHttpReply
{
public:
StreamHttpAuthenticateReply(Stream& stream, const String& contentType);
virtual void send();
};
#endif
//------------------------------------------------------------------------------
// Class Declaration
//------------------------------------------------------------------------------
//! Normal reply.
class StreamHttpReply: public AbstractStreamHttpReply
{
public:
StreamHttpReply(Stream& stream, const String& contentType);
virtual void send(const String& data, const bool gzipencoded=false) { AbstractStreamHttpReply::send(data, "OK"); };
};
}
#endif // __ArduinoHttpServer__StreamHttpReply__