ESP32 HTTPS Server
HTTPResponse.hpp
1 #ifndef SRC_HTTPRESPONSE_HPP_
2 #define SRC_HTTPRESPONSE_HPP_
3 
4 #include <Arduino.h>
5 #include <string>
6 // Arduino declares it's own min max, incompatible with the stl...
7 #undef min
8 #undef max
9 #undef write
10 #include <vector>
11 
12 #include <openssl/ssl.h>
13 
14 #include "util.hpp"
15 
16 #include "ConnectionContext.hpp"
17 #include "HTTPHeaders.hpp"
18 #include "HTTPHeader.hpp"
19 
20 namespace httpsserver {
21 
25 class HTTPResponse : public Print {
26 public:
28  virtual ~HTTPResponse();
29 
30  void setStatusCode(uint16_t statusCode);
31  void setStatusText(std::string const &statusText);
32  uint16_t getStatusCode();
33  std::string getStatusText();
34  void setHeader(std::string const &name, std::string const &value);
35  std::string getHeader(std::string const &name);
36  bool isHeaderWritten();
37 
38  void printStd(std::string const &str);
39 
40  // From Print:
41  size_t write(const uint8_t *buffer, size_t size);
42  size_t write(uint8_t);
43 
44  void error();
45 
46  bool isResponseBuffered();
47  void finalize();
48 
49  ConnectionContext * _con;
50 
51 private:
52  void printHeader();
53  void printInternal(const std::string &str, bool skipBuffer = false);
54  size_t writeBytesInternal(const void * data, int length, bool skipBuffer = false);
55  void drainBuffer(bool onOverflow = false);
56 
57  uint16_t _statusCode;
58  std::string _statusText;
59  HTTPHeaders _headers;
60  bool _headerWritten;
61  bool _isError;
62 
63  // Response cache
64  byte * _responseCache;
65  size_t _responseCacheSize;
66  size_t _responseCachePointer;
67 };
68 
69 } /* namespace httpsserver */
70 
71 #endif /* SRC_HTTPRESPONSE_HPP_ */
void error()
Definition: HTTPResponse.cpp:131
Represents the response stream of an HTTP request.
Definition: HTTPResponse.hpp:25
size_t write(const uint8_t *buffer, size_t size)
Definition: HTTPResponse.cpp:88
Groups and manages a set of HTTPHeader instances.
Definition: HTTPHeaders.hpp:18
void printStd(std::string const &str)
Definition: HTTPResponse.cpp:81
Internal class to handle the state of a connection.
Definition: ConnectionContext.hpp:18
Definition: ConnectionContext.cpp:3