Add optional support for CORS headers (#2688)

* add support for CORS headers

* remove accidental function impl

* rename setCORS to enableCORS, and add aliased function enableCrossOrigin
This commit is contained in:
Victor Aprea
2019-04-22 14:52:39 -04:00
committed by Me No Dev
parent f8eebb5c39
commit 672e4faa92
2 changed files with 22 additions and 5 deletions

View File

@ -122,6 +122,9 @@ public:
void send_P(int code, PGM_P content_type, PGM_P content);
void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength);
void enableCORS(boolean value = true);
void enableCrossOrigin(boolean value = true);
void setContentLength(const size_t contentLength);
void sendHeader(const String& name, const String& value, bool first = false);
void sendContent(const String& content);
@ -130,12 +133,12 @@ public:
static String urlDecode(const String& text);
template<typename T>
template<typename T>
size_t streamFile(T &file, const String& contentType) {
_streamFileCore(file.size(), file.name(), contentType);
return _currentClient.write(file);
}
protected:
virtual size_t _currentClientWrite(const char* b, size_t l) { return _currentClient.write( b, l ); }
virtual size_t _currentClientWrite_P(PGM_P b, size_t l) { return _currentClient.write_P( b, l ); }
@ -151,7 +154,7 @@ protected:
int _uploadReadByte(WiFiClient& client);
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
bool _collectHeader(const char* headerName, const char* headerValue);
void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType);
String _getRandomHexString();
@ -163,6 +166,7 @@ protected:
String value;
};
boolean _corsEnabled;
WiFiServer _server;
WiFiClient _currentClient;