mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
additional mimetable fixes, additional string moves to progmem (#4371)
This commit is contained in:
parent
bb90e12ea0
commit
5328a8b91e
@ -36,11 +36,9 @@
|
|||||||
#define DEBUG_OUTPUT Serial
|
#define DEBUG_OUTPUT Serial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//const char * AUTHORIZATION_HEADER = "Authorization";
|
|
||||||
static const char AUTHORIZATION_HEADER[] PROGMEM = "Authorization";
|
static const char AUTHORIZATION_HEADER[] PROGMEM = "Authorization";
|
||||||
static const char qop_auth[] PROGMEM = "qop=auth";
|
static const char qop_auth[] PROGMEM = "qop=auth";
|
||||||
static const char WWW_Authenticate[] PROGMEM = "WWW-Authenticate";
|
static const char WWW_Authenticate[] PROGMEM = "WWW-Authenticate";
|
||||||
static const char colon[] PROGMEM = ":";
|
|
||||||
static const char Content_Length[] PROGMEM = "Content-Length";
|
static const char Content_Length[] PROGMEM = "Content-Length";
|
||||||
|
|
||||||
|
|
||||||
@ -81,10 +79,9 @@ ESP8266WebServer::ESP8266WebServer(int port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ESP8266WebServer::~ESP8266WebServer() {
|
ESP8266WebServer::~ESP8266WebServer() {
|
||||||
close();
|
_server.close();
|
||||||
if (_currentHeaders)
|
if (_currentHeaders)
|
||||||
delete[]_currentHeaders;
|
delete[]_currentHeaders;
|
||||||
_headerKeysCount = 0;
|
|
||||||
RequestHandler* handler = _firstHandler;
|
RequestHandler* handler = _firstHandler;
|
||||||
while (handler) {
|
while (handler) {
|
||||||
RequestHandler* next = handler->next();
|
RequestHandler* next = handler->next();
|
||||||
@ -195,9 +192,9 @@ bool ESP8266WebServer::authenticate(const char * username, const char * password
|
|||||||
#endif
|
#endif
|
||||||
md5.begin();
|
md5.begin();
|
||||||
if(authReq.indexOf(FPSTR(qop_auth)) != -1) {
|
if(authReq.indexOf(FPSTR(qop_auth)) != -1) {
|
||||||
md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _nc + FPSTR(colon) + _cnonce + ":auth:" + _H2);
|
md5.add(_H1 + ':' + _nonce + ':' + _nc + ':' + _cnonce + F(":auth:") + _H2);
|
||||||
} else {
|
} else {
|
||||||
md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _H2);
|
md5.add(_H1 + ':' + _nonce + ':' + _H2);
|
||||||
}
|
}
|
||||||
md5.calculate();
|
md5.calculate();
|
||||||
String _responsecheck = md5.toString();
|
String _responsecheck = md5.toString();
|
||||||
@ -237,7 +234,7 @@ void ESP8266WebServer::requestAuthentication(HTTPAuthMethod mode, const char* re
|
|||||||
sendHeader(String(FPSTR(WWW_Authenticate)), String(F("Digest realm=\"")) +_srealm + String(F("\", qop=\"auth\", nonce=\"")) + _snonce + String(F("\", opaque=\"")) + _sopaque + String(F("\"")));
|
sendHeader(String(FPSTR(WWW_Authenticate)), String(F("Digest realm=\"")) +_srealm + String(F("\", qop=\"auth\", nonce=\"")) + _snonce + String(F("\", opaque=\"")) + _sopaque + String(F("\"")));
|
||||||
}
|
}
|
||||||
using namespace mime;
|
using namespace mime;
|
||||||
send(401, mimeTable[html].mimeType, authFailMsg);
|
send(401, String(FPSTR(mimeTable[html].mimeType)), authFailMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WebServer::on(const String &uri, ESP8266WebServer::THandlerFunction handler) {
|
void ESP8266WebServer::on(const String &uri, ESP8266WebServer::THandlerFunction handler) {
|
||||||
@ -603,7 +600,7 @@ void ESP8266WebServer::_handleRequest() {
|
|||||||
}
|
}
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
using namespace mime;
|
using namespace mime;
|
||||||
send(404, mimeTable[html].mimeType, String(F("Not found: ")) + _currentUri);
|
send(404, String(FPSTR(mimeTable[html].mimeType)), String(F("Not found: ")) + _currentUri);
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
if (handled) {
|
if (handled) {
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "WiFiServer.h"
|
#include "WiFiServer.h"
|
||||||
#include "WiFiClient.h"
|
#include "WiFiClient.h"
|
||||||
#include "ESP8266WebServer.h"
|
#include "ESP8266WebServer.h"
|
||||||
|
#include "detail/mimetable.h"
|
||||||
|
|
||||||
//#define DEBUG_ESP_HTTP_SERVER
|
//#define DEBUG_ESP_HTTP_SERVER
|
||||||
#ifdef DEBUG_ESP_PORT
|
#ifdef DEBUG_ESP_PORT
|
||||||
@ -31,6 +32,9 @@
|
|||||||
#define DEBUG_OUTPUT Serial
|
#define DEBUG_OUTPUT Serial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char Content_Type[] PROGMEM = "Content-Type";
|
||||||
|
static const char filename[] PROGMEM = "filename";
|
||||||
|
|
||||||
static char* readBytesWithTimeout(WiFiClient& client, size_t maxLength, size_t& dataLength, int timeout_ms)
|
static char* readBytesWithTimeout(WiFiClient& client, size_t maxLength, size_t& dataLength, int timeout_ms)
|
||||||
{
|
{
|
||||||
char *buf = nullptr;
|
char *buf = nullptr;
|
||||||
@ -98,15 +102,15 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
|||||||
_chunked = false;
|
_chunked = false;
|
||||||
|
|
||||||
HTTPMethod method = HTTP_GET;
|
HTTPMethod method = HTTP_GET;
|
||||||
if (methodStr == "POST") {
|
if (methodStr == F("POST")) {
|
||||||
method = HTTP_POST;
|
method = HTTP_POST;
|
||||||
} else if (methodStr == "DELETE") {
|
} else if (methodStr == F("DELETE")) {
|
||||||
method = HTTP_DELETE;
|
method = HTTP_DELETE;
|
||||||
} else if (methodStr == "OPTIONS") {
|
} else if (methodStr == F("OPTIONS")) {
|
||||||
method = HTTP_OPTIONS;
|
method = HTTP_OPTIONS;
|
||||||
} else if (methodStr == "PUT") {
|
} else if (methodStr == F("PUT")) {
|
||||||
method = HTTP_PUT;
|
method = HTTP_PUT;
|
||||||
} else if (methodStr == "PATCH") {
|
} else if (methodStr == F("PATCH")) {
|
||||||
method = HTTP_PATCH;
|
method = HTTP_PATCH;
|
||||||
}
|
}
|
||||||
_currentMethod = method;
|
_currentMethod = method;
|
||||||
@ -158,20 +162,21 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
|||||||
DEBUG_OUTPUT.println(headerValue);
|
DEBUG_OUTPUT.println(headerValue);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (headerName.equalsIgnoreCase("Content-Type")){
|
if (headerName.equalsIgnoreCase(FPSTR(Content_Type))){
|
||||||
if (headerValue.startsWith("text/plain")){
|
using namespace mime;
|
||||||
|
if (headerValue.startsWith(FPSTR(mimeTable[txt].mimeType))){
|
||||||
isForm = false;
|
isForm = false;
|
||||||
} else if (headerValue.startsWith("application/x-www-form-urlencoded")){
|
} else if (headerValue.startsWith(F("application/x-www-form-urlencoded"))){
|
||||||
isForm = false;
|
isForm = false;
|
||||||
isEncoded = true;
|
isEncoded = true;
|
||||||
} else if (headerValue.startsWith("multipart/")){
|
} else if (headerValue.startsWith(F("multipart/"))){
|
||||||
boundaryStr = headerValue.substring(headerValue.indexOf('=') + 1);
|
boundaryStr = headerValue.substring(headerValue.indexOf('=') + 1);
|
||||||
boundaryStr.replace("\"","");
|
boundaryStr.replace("\"","");
|
||||||
isForm = true;
|
isForm = true;
|
||||||
}
|
}
|
||||||
} else if (headerName.equalsIgnoreCase("Content-Length")){
|
} else if (headerName.equalsIgnoreCase(F("Content-Length"))){
|
||||||
contentLength = headerValue.toInt();
|
contentLength = headerValue.toInt();
|
||||||
} else if (headerName.equalsIgnoreCase("Host")){
|
} else if (headerName.equalsIgnoreCase(F("Host"))){
|
||||||
_hostHeader = headerValue;
|
_hostHeader = headerValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +198,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
|||||||
if(!isEncoded){
|
if(!isEncoded){
|
||||||
//plain post json or other data
|
//plain post json or other data
|
||||||
RequestArgument& arg = _currentArgs[_currentArgCount++];
|
RequestArgument& arg = _currentArgs[_currentArgCount++];
|
||||||
arg.key = "plain";
|
arg.key = F("plain");
|
||||||
arg.value = String(plainBuf);
|
arg.value = String(plainBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,7 +394,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
|
|||||||
|
|
||||||
line = client.readStringUntil('\r');
|
line = client.readStringUntil('\r');
|
||||||
client.readStringUntil('\n');
|
client.readStringUntil('\n');
|
||||||
if (line.length() > 19 && line.substring(0, 19).equalsIgnoreCase("Content-Disposition")){
|
if (line.length() > 19 && line.substring(0, 19).equalsIgnoreCase(F("Content-Disposition"))){
|
||||||
int nameStart = line.indexOf('=');
|
int nameStart = line.indexOf('=');
|
||||||
if (nameStart != -1){
|
if (nameStart != -1){
|
||||||
argName = line.substring(nameStart+2);
|
argName = line.substring(nameStart+2);
|
||||||
@ -405,16 +410,18 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
|
|||||||
DEBUG_OUTPUT.println(argFilename);
|
DEBUG_OUTPUT.println(argFilename);
|
||||||
#endif
|
#endif
|
||||||
//use GET to set the filename if uploading using blob
|
//use GET to set the filename if uploading using blob
|
||||||
if (argFilename == "blob" && hasArg("filename")) argFilename = arg("filename");
|
if (argFilename == F("blob") && hasArg(FPSTR(filename)))
|
||||||
|
argFilename = arg(FPSTR(filename));
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_ESP_HTTP_SERVER
|
#ifdef DEBUG_ESP_HTTP_SERVER
|
||||||
DEBUG_OUTPUT.print("PostArg Name: ");
|
DEBUG_OUTPUT.print("PostArg Name: ");
|
||||||
DEBUG_OUTPUT.println(argName);
|
DEBUG_OUTPUT.println(argName);
|
||||||
#endif
|
#endif
|
||||||
argType = "text/plain";
|
using namespace mime;
|
||||||
|
argType = FPSTR(mimeTable[txt].mimeType);
|
||||||
line = client.readStringUntil('\r');
|
line = client.readStringUntil('\r');
|
||||||
client.readStringUntil('\n');
|
client.readStringUntil('\n');
|
||||||
if (line.length() > 12 && line.substring(0, 12).equalsIgnoreCase("Content-Type")){
|
if (line.length() > 12 && line.substring(0, 12).equalsIgnoreCase(FPSTR(Content_Type))){
|
||||||
argType = line.substring(line.indexOf(':')+2);
|
argType = line.substring(line.indexOf(':')+2);
|
||||||
//skip next line
|
//skip next line
|
||||||
client.readStringUntil('\r');
|
client.readStringUntil('\r');
|
||||||
@ -559,7 +566,8 @@ readfile:
|
|||||||
arg.value = postArgs[iarg].value;
|
arg.value = postArgs[iarg].value;
|
||||||
}
|
}
|
||||||
_currentArgCount = iarg;
|
_currentArgCount = iarg;
|
||||||
if (postArgs) delete[] postArgs;
|
if (postArgs)
|
||||||
|
delete[] postArgs;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_ESP_HTTP_SERVER
|
#ifdef DEBUG_ESP_HTTP_SERVER
|
||||||
|
@ -91,7 +91,8 @@ public:
|
|||||||
if (!_isFile) {
|
if (!_isFile) {
|
||||||
// Base URI doesn't point to a file.
|
// Base URI doesn't point to a file.
|
||||||
// If a directory is requested, look for index file.
|
// If a directory is requested, look for index file.
|
||||||
if (requestUri.endsWith("/")) requestUri += "index.htm";
|
if (requestUri.endsWith("/"))
|
||||||
|
requestUri += "index.htm";
|
||||||
|
|
||||||
// Append whatever follows this URI in request to get the file path.
|
// Append whatever follows this URI in request to get the file path.
|
||||||
path += requestUri.substring(_baseUriLength);
|
path += requestUri.substring(_baseUriLength);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user