mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Make file uploads using curl fail less often
This commit is contained in:
parent
c355f626f2
commit
278c980ed8
@ -111,7 +111,7 @@ protected:
|
||||
bool _parseRequest(WiFiClient& client);
|
||||
void _parseArguments(String data);
|
||||
static const char* _responseCodeToString(int code);
|
||||
void _parseForm(WiFiClient& client, String boundary, uint32_t len);
|
||||
bool _parseForm(WiFiClient& client, String boundary, uint32_t len);
|
||||
void _uploadWriteByte(uint8_t b);
|
||||
uint8_t _uploadReadByte(WiFiClient& client);
|
||||
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include "WiFiClient.h"
|
||||
#include "ESP8266WebServer.h"
|
||||
|
||||
// #define DEBUG
|
||||
#define DEBUG_OUTPUT Serial1
|
||||
#define DEBUG
|
||||
#define DEBUG_OUTPUT Serial
|
||||
|
||||
bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
||||
// Read the first line of HTTP request
|
||||
@ -103,6 +103,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
||||
}
|
||||
} else if (headerName == "Content-Length"){
|
||||
contentLength = headerValue.toInt();
|
||||
Serial.printf("Content-Length: %d\r\n", contentLength);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +132,9 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
||||
}
|
||||
_parseArguments(searchStr);
|
||||
if (isForm){
|
||||
_parseForm(client, boundaryStr, contentLength);
|
||||
if (!_parseForm(client, boundaryStr, contentLength)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_parseArguments(searchStr);
|
||||
@ -242,7 +245,7 @@ uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
|
||||
return (uint8_t)res;
|
||||
}
|
||||
|
||||
void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
|
||||
bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
|
||||
|
||||
#ifdef DEBUG
|
||||
DEBUG_OUTPUT.print("Parse Form: Boundary: ");
|
||||
@ -251,7 +254,12 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
|
||||
DEBUG_OUTPUT.println(len);
|
||||
#endif
|
||||
String line;
|
||||
line = client.readStringUntil('\r');
|
||||
int retry = 0;
|
||||
do {
|
||||
line = client.readStringUntil('\r');
|
||||
++retry;
|
||||
} while (line.length() == 0 && retry < 3);
|
||||
|
||||
client.readStringUntil('\n');
|
||||
//start reading the form
|
||||
if (line == ("--"+boundary)){
|
||||
@ -429,7 +437,11 @@ readfile:
|
||||
}
|
||||
_currentArgCount = iarg;
|
||||
if (postArgs) delete[] postArgs;
|
||||
return true;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
DEBUG_OUTPUT.print("Error: line: ");
|
||||
DEBUG_OUTPUT.println(line);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user