1212#include < deque>
1313#include < functional>
1414#include < list>
15+ #include < optional>
1516#include < unordered_map>
1617#include < vector>
1718
@@ -136,9 +137,15 @@ class AsyncWebHeader {
136137
137138public:
138139 AsyncWebHeader (const AsyncWebHeader &) = default ;
140+ AsyncWebHeader (AsyncWebHeader &&) = default ;
139141 AsyncWebHeader (const char *name, const char *value) : _name(name), _value(value) {}
140142 AsyncWebHeader (const String &name, const String &value) : _name(name), _value(value) {}
141- AsyncWebHeader (const String &data);
143+
144+ #ifndef ESP8266
145+ [[deprecated("Use AsyncWebHeader::parse(data) instead")]]
146+ #endif
147+ AsyncWebHeader (const String &data)
148+ : AsyncWebHeader(parse(data).value_or(AsyncWebHeader(emptyString, emptyString))) {};
142149
143150 AsyncWebHeader &operator =(const AsyncWebHeader &) = default ;
144151
@@ -148,7 +155,13 @@ class AsyncWebHeader {
148155 const String &value () const {
149156 return _value;
150157 }
158+
151159 String toString () const ;
160+
161+ static std::optional<AsyncWebHeader> parse (const String &data) {
162+ return parse (data.c_str ());
163+ }
164+ static std::optional<AsyncWebHeader> parse (const char *data);
152165};
153166
154167/*
@@ -293,8 +306,9 @@ class AsyncWebServerRequest {
293306 RequestedConnectionType requestedConnType () const {
294307 return _reqconntype;
295308 }
296- bool isExpectedRequestedConnType (RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED , RequestedConnectionType erct3 = RCT_NOT_USED )
297- const ;
309+ bool isExpectedRequestedConnType (
310+ RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED , RequestedConnectionType erct3 = RCT_NOT_USED
311+ ) const ;
298312 bool isWebSocketUpgrade () const {
299313 return _method == HTTP_GET && isExpectedRequestedConnType (RCT_WS );
300314 }
@@ -482,7 +496,8 @@ class AsyncWebServerRequest {
482496 return beginResponse (code, contentType.c_str (), content, len, callback);
483497 }
484498#ifndef ESP8266
485- [[deprecated(" Replaced by beginResponse(int code, const String& contentType, const char* content = asyncsrv::empty, AwsTemplateProcessor callback = nullptr)"
499+ [[deprecated(
500+ " Replaced by beginResponse(int code, const String& contentType, const char* content = asyncsrv::empty, AwsTemplateProcessor callback = nullptr)"
486501 )]]
487502#endif
488503 AsyncWebServerResponse *beginResponse_P (int code, const String &contentType, PGM_P content, AwsTemplateProcessor callback = nullptr );
@@ -1038,6 +1053,10 @@ class AsyncWebServerResponse {
10381053 setContentType (type.c_str ());
10391054 }
10401055 void setContentType (const char *type);
1056+ bool addHeader (AsyncWebHeader &&header, bool replaceExisting = true );
1057+ bool addHeader (const AsyncWebHeader &header, bool replaceExisting = true ) {
1058+ return addHeader (header.name (), header.value (), replaceExisting);
1059+ }
10411060 bool addHeader (const char *name, const char *value, bool replaceExisting = true );
10421061 bool addHeader (const String &name, const String &value, bool replaceExisting = true ) {
10431062 return addHeader (name.c_str (), value.c_str (), replaceExisting);
0 commit comments