Pokus o nejnovejsi upravy kvuli ESP32 - nutno overit na ESP8266!!
This commit is contained in:
@ -24,6 +24,8 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include "FS.h"
|
||||
|
||||
#include "StringArray.h"
|
||||
@ -59,22 +61,14 @@ class AsyncResponseStream;
|
||||
|
||||
#ifndef WEBSERVER_H
|
||||
typedef enum {
|
||||
HTTP_GET = 0b0000000000000001,
|
||||
HTTP_POST = 0b0000000000000010,
|
||||
HTTP_DELETE = 0b0000000000000100,
|
||||
HTTP_PUT = 0b0000000000001000,
|
||||
HTTP_PATCH = 0b0000000000010000,
|
||||
HTTP_HEAD = 0b0000000000100000,
|
||||
HTTP_OPTIONS = 0b0000000001000000,
|
||||
HTTP_PROPFIND = 0b0000000010000000,
|
||||
HTTP_LOCK = 0b0000000100000000,
|
||||
HTTP_UNLOCK = 0b0000001000000000,
|
||||
HTTP_PROPPATCH = 0b0000010000000000,
|
||||
HTTP_MKCOL = 0b0000100000000000,
|
||||
HTTP_MOVE = 0b0001000000000000,
|
||||
HTTP_COPY = 0b0010000000000000,
|
||||
HTTP_RESERVED = 0b0100000000000000,
|
||||
HTTP_ANY = 0b0111111111111111,
|
||||
HTTP_GET = 0b00000001,
|
||||
HTTP_POST = 0b00000010,
|
||||
HTTP_DELETE = 0b00000100,
|
||||
HTTP_PUT = 0b00001000,
|
||||
HTTP_PATCH = 0b00010000,
|
||||
HTTP_HEAD = 0b00100000,
|
||||
HTTP_OPTIONS = 0b01000000,
|
||||
HTTP_ANY = 0b01111111,
|
||||
} WebRequestMethod;
|
||||
#endif
|
||||
|
||||
@ -94,7 +88,7 @@ namespace fs {
|
||||
//if this value is returned when asked for data, packet will not be sent and you will be asked for data again
|
||||
#define RESPONSE_TRY_AGAIN 0xFFFFFFFF
|
||||
|
||||
typedef uint16_t WebRequestMethodComposite;
|
||||
typedef uint8_t WebRequestMethodComposite;
|
||||
typedef std::function<void(void)> ArDisconnectHandler;
|
||||
|
||||
/*
|
||||
@ -129,6 +123,9 @@ class AsyncWebHeader {
|
||||
String _value;
|
||||
|
||||
public:
|
||||
AsyncWebHeader() = default;
|
||||
AsyncWebHeader(const AsyncWebHeader &) = default;
|
||||
|
||||
AsyncWebHeader(const String& name, const String& value): _name(name), _value(value){}
|
||||
AsyncWebHeader(const String& data): _name(), _value(){
|
||||
if(!data) return;
|
||||
@ -137,10 +134,12 @@ class AsyncWebHeader {
|
||||
_name = data.substring(0, index);
|
||||
_value = data.substring(index + 2);
|
||||
}
|
||||
~AsyncWebHeader(){}
|
||||
|
||||
AsyncWebHeader &operator=(const AsyncWebHeader &) = default;
|
||||
|
||||
const String& name() const { return _name; }
|
||||
const String& value() const { return _value; }
|
||||
String toString() const { return String(_name + F(": ") + _value + F("\r\n")); }
|
||||
String toString() const { return _name + F(": ") + _value + F("\r\n"); }
|
||||
};
|
||||
|
||||
/*
|
||||
@ -162,7 +161,7 @@ class AsyncWebServerRequest {
|
||||
AsyncWebServer* _server;
|
||||
AsyncWebHandler* _handler;
|
||||
AsyncWebServerResponse* _response;
|
||||
StringArray _interestingHeaders;
|
||||
std::vector<String> _interestingHeaders;
|
||||
ArDisconnectHandler _onDisconnectfn;
|
||||
|
||||
String _temp;
|
||||
@ -184,9 +183,9 @@ class AsyncWebServerRequest {
|
||||
size_t _contentLength;
|
||||
size_t _parsedLength;
|
||||
|
||||
LinkedList<AsyncWebHeader *> _headers;
|
||||
std::list<AsyncWebHeader> _headers;
|
||||
LinkedList<AsyncWebParameter *> _params;
|
||||
LinkedList<String *> _pathParams;
|
||||
std::vector<String> _pathParams;
|
||||
|
||||
uint8_t _multiParseState;
|
||||
uint8_t _boundaryPosition;
|
||||
@ -278,9 +277,12 @@ class AsyncWebServerRequest {
|
||||
bool hasHeader(const String& name) const; // check if header exists
|
||||
bool hasHeader(const __FlashStringHelper * data) const; // check if header exists
|
||||
|
||||
AsyncWebHeader* getHeader(const String& name) const;
|
||||
AsyncWebHeader* getHeader(const __FlashStringHelper * data) const;
|
||||
AsyncWebHeader* getHeader(size_t num) const;
|
||||
AsyncWebHeader* getHeader(const String& name);
|
||||
const AsyncWebHeader* getHeader(const String& name) const;
|
||||
AsyncWebHeader* getHeader(const __FlashStringHelper * data);
|
||||
const AsyncWebHeader* getHeader(const __FlashStringHelper * data) const;
|
||||
AsyncWebHeader* getHeader(size_t num);
|
||||
const AsyncWebHeader* getHeader(size_t num) const;
|
||||
|
||||
size_t params() const; // get arguments count
|
||||
bool hasParam(const String& name, bool post=false, bool file=false) const;
|
||||
@ -379,7 +381,7 @@ typedef enum {
|
||||
class AsyncWebServerResponse {
|
||||
protected:
|
||||
int _code;
|
||||
LinkedList<AsyncWebHeader *> _headers;
|
||||
std::list<AsyncWebHeader> _headers;
|
||||
String _contentType;
|
||||
size_t _contentLength;
|
||||
bool _sendContentLength;
|
||||
@ -462,17 +464,16 @@ class AsyncWebServer {
|
||||
};
|
||||
|
||||
class DefaultHeaders {
|
||||
using headers_t = LinkedList<AsyncWebHeader *>;
|
||||
using headers_t = std::list<AsyncWebHeader>;
|
||||
headers_t _headers;
|
||||
|
||||
DefaultHeaders()
|
||||
:_headers(headers_t([](AsyncWebHeader *h){ delete h; }))
|
||||
{}
|
||||
public:
|
||||
using ConstIterator = headers_t::ConstIterator;
|
||||
DefaultHeaders() = default;
|
||||
|
||||
using ConstIterator = headers_t::const_iterator;
|
||||
|
||||
void addHeader(const String& name, const String& value){
|
||||
_headers.add(new AsyncWebHeader(name, value));
|
||||
_headers.emplace_back(name, value);
|
||||
}
|
||||
|
||||
ConstIterator begin() const { return _headers.begin(); }
|
||||
@ -480,6 +481,7 @@ public:
|
||||
|
||||
DefaultHeaders(DefaultHeaders const &) = delete;
|
||||
DefaultHeaders &operator=(DefaultHeaders const &) = delete;
|
||||
|
||||
static DefaultHeaders &Instance() {
|
||||
static DefaultHeaders instance;
|
||||
return instance;
|
||||
|
Reference in New Issue
Block a user