Files
ESPAsyncWebServer/src/WebResponseImpl.h

100 lines
3.4 KiB
C
Raw Normal View History

2015-12-19 18:53:33 +02:00
/*
Asynchronous WebServer library for Espressif MCUs
2015-12-19 18:53:33 +02:00
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
2015-12-19 18:53:33 +02:00
#ifndef ASYNCWEBSERVERRESPONSEIMPL_H_
#define ASYNCWEBSERVERRESPONSEIMPL_H_
class AsyncBasicResponse: public AsyncWebServerResponse {
private:
String _content;
public:
AsyncBasicResponse(int code, String contentType=String(), String content=String());
void _respond(AsyncWebServerRequest *request);
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
2016-04-08 17:43:16 +03:00
bool _sourceValid(){ return true; }
2015-12-19 18:53:33 +02:00
};
2015-12-19 20:48:53 +02:00
class AsyncAbstractResponse: public AsyncWebServerResponse {
private:
String _head;
public:
void _respond(AsyncWebServerRequest *request);
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
2016-04-08 17:43:16 +03:00
bool _sourceValid(){ return false; }
2015-12-19 20:48:53 +02:00
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen){ return 0; }
};
class AsyncFileResponse: public AsyncAbstractResponse {
2015-12-19 18:53:33 +02:00
private:
File _content;
String _path;
void _setContentType(String path);
public:
AsyncFileResponse(FS &fs, String path, String contentType=String(), bool download=false);
AsyncFileResponse(File content, String path, String contentType=String(), bool download=false);
2015-12-19 18:53:33 +02:00
~AsyncFileResponse();
2015-12-19 20:48:53 +02:00
bool _sourceValid(){ return !!(_content); }
size_t _fillBuffer(uint8_t *buf, size_t maxLen);
2015-12-19 18:53:33 +02:00
};
2015-12-19 20:48:53 +02:00
class AsyncStreamResponse: public AsyncAbstractResponse {
2015-12-19 18:53:33 +02:00
private:
Stream *_content;
public:
AsyncStreamResponse(Stream &stream, String contentType, size_t len);
2015-12-19 20:48:53 +02:00
bool _sourceValid(){ return !!(_content); }
size_t _fillBuffer(uint8_t *buf, size_t maxLen);
2015-12-19 18:53:33 +02:00
};
2015-12-19 20:48:53 +02:00
class AsyncCallbackResponse: public AsyncAbstractResponse {
2015-12-19 18:53:33 +02:00
private:
AwsResponseFiller _content;
public:
AsyncCallbackResponse(String contentType, size_t len, AwsResponseFiller callback);
2015-12-19 20:48:53 +02:00
bool _sourceValid(){ return !!(_content); }
size_t _fillBuffer(uint8_t *buf, size_t maxLen);
2015-12-19 18:53:33 +02:00
};
class AsyncChunkedResponse: public AsyncAbstractResponse {
private:
AwsResponseFiller _content;
public:
AsyncChunkedResponse(String contentType, AwsResponseFiller callback);
bool _sourceValid(){ return !!(_content); }
size_t _fillBuffer(uint8_t *buf, size_t maxLen);
};
2016-01-22 18:06:23 +02:00
class cbuf;
2016-01-19 21:47:26 +02:00
class AsyncResponseStream: public AsyncAbstractResponse, public Print {
private:
cbuf *_content;
public:
AsyncResponseStream(String contentType, size_t bufferSize);
2016-01-19 21:47:26 +02:00
~AsyncResponseStream();
bool _sourceValid(){ return (_state < RESPONSE_END); }
size_t _fillBuffer(uint8_t *buf, size_t maxLen);
size_t write(const uint8_t *data, size_t len);
size_t write(uint8_t data);
using Print::write;
2016-01-19 21:47:26 +02:00
};
2015-12-19 18:53:33 +02:00
#endif /* ASYNCWEBSERVERRESPONSEIMPL_H_ */