1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Web server refactoring

This commit is contained in:
Ivan Grokhotkov
2015-05-14 13:33:12 +03:00
parent eb37830238
commit 36d0968ada
5 changed files with 574 additions and 507 deletions

View File

@ -29,14 +29,17 @@
enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE };
enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END };
#define PAYLOAD_UNIT_SIZE 1460
typedef struct {
HTTPUploadStatus status;
String filename;
String name;
String type;
size_t size;
size_t buflen;
uint8_t buf[1460];
size_t totalSize; // file size
size_t currentSize; // size of data currently in buf
uint8_t buf[PAYLOAD_UNIT_SIZE];
} HTTPUpload;
class ESP8266WebServer
@ -58,7 +61,7 @@ public:
String uri() { return _currentUri; }
HTTPMethod method() { return _currentMethod; }
WiFiClient client() { return _currentClient; }
HTTPUpload upload() { return _currentUpload; }
HTTPUpload& upload() { return _currentUpload; }
String arg(const char* name); // get request argument value by name
String arg(int i); // get request argument value by number
@ -72,11 +75,13 @@ public:
// content - actual content body
void send(int code, const char* content_type = NULL, String content = String(""));
void sendHeader(String name, String value, bool first = false);
void sendContent(String content);
protected:
void _handleRequest(WiFiClient& client, String uri, HTTPMethod method);
void _handleRequest();
bool _parseRequest(WiFiClient& client);
void _parseArguments(String data);
static const char* _responseCodeToString(int code);
static void _appendHeader(String& response, const char* name, const char* value);
void _parseForm(WiFiClient& client, String boundary, uint32_t len);
struct RequestHandler;
@ -95,6 +100,8 @@ protected:
RequestArgument* _currentArgs;
HTTPUpload _currentUpload;
String _responseHeaders;
RequestHandler* _firstHandler;
RequestHandler* _lastHandler;
THandlerFunction _notFoundHandler;