mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
add proper POST support and more methods
GET params are always added plain POST is added to the GET arguments Uploads are handled by separate handler
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
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
|
||||
Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
|
||||
*/
|
||||
|
||||
|
||||
@ -25,8 +26,18 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_POST };
|
||||
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 };
|
||||
|
||||
typedef struct {
|
||||
HTTPUploadStatus status;
|
||||
String filename;
|
||||
String name;
|
||||
String type;
|
||||
size_t size;
|
||||
size_t buflen;
|
||||
uint8_t buf[1460];
|
||||
} HTTPUpload;
|
||||
|
||||
class ESP8266WebServer
|
||||
{
|
||||
@ -42,10 +53,12 @@ public:
|
||||
void on(const char* uri, THandlerFunction handler);
|
||||
void on(const char* uri, HTTPMethod method, THandlerFunction fn);
|
||||
void onNotFound(THandlerFunction fn); //called when handler is not assigned
|
||||
void onFileUpload(THandlerFunction fn); //handle file uploads
|
||||
|
||||
String uri() { return _currentUri; }
|
||||
HTTPMethod method() { return _currentMethod; }
|
||||
WiFiClient client() { return _currentClient; }
|
||||
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
|
||||
@ -64,6 +77,7 @@ protected:
|
||||
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;
|
||||
struct RequestArgument {
|
||||
@ -79,10 +93,12 @@ protected:
|
||||
|
||||
size_t _currentArgCount;
|
||||
RequestArgument* _currentArgs;
|
||||
HTTPUpload _currentUpload;
|
||||
|
||||
RequestHandler* _firstHandler;
|
||||
RequestHandler* _lastHandler;
|
||||
THandlerFunction _notFoundHandler;
|
||||
THandlerFunction _fileUploadHandler;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user