1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

small addons (#5847)

* make (static) ESP8266WebServer::responseCodeToString visible and usable
* esp8266:coreVersionNumeric(): add a define and comment-example to check on its usability
This commit is contained in:
david gauchard 2019-03-07 11:37:38 +01:00 committed by GitHub
parent b1da9eda46
commit 2528013c5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -22,6 +22,8 @@
#ifndef __CORE_ESP8266_VERSION_H #ifndef __CORE_ESP8266_VERSION_H
#define __CORE_ESP8266_VERSION_H #define __CORE_ESP8266_VERSION_H
#define HAS_ESP8266_VERSION_NUMERIC 1
#include <core_version.h> #include <core_version.h>
#define __STRHELPER(x) #x #define __STRHELPER(x) #x
@ -52,6 +54,20 @@ extern "C++"
// esp8266CoreVersionSubRevision() is 3 Numeric is: 20499903 // esp8266CoreVersionSubRevision() is 3 Numeric is: 20499903
// case 2.5.0: // case 2.5.0:
// esp8266CoreVersionSubRevision() is 0 Numeric is: 20500000 // esp8266CoreVersionSubRevision() is 0 Numeric is: 20500000
//
// Using esp8266::coreVersionNumeric() in a portable way:
//
// #if HAS_ESP8266_VERSION_NUMERIC
// if (esp8266::coreVersionNumeric() >= 20500042)
// {
// // modern api can be used
// }
// else
// #endif
// {
// // code using older api
// // (will not be compiled in when newer api is usable)
// }
namespace conststr { namespace conststr {

View File

@ -371,7 +371,7 @@ void ESP8266WebServer::_prepareHeader(String& response, int code, const char* co
response = String(F("HTTP/1.")) + String(_currentVersion) + ' '; response = String(F("HTTP/1.")) + String(_currentVersion) + ' ';
response += String(code); response += String(code);
response += ' '; response += ' ';
response += _responseCodeToString(code); response += responseCodeToString(code);
response += "\r\n"; response += "\r\n";
using namespace mime; using namespace mime;
@ -625,7 +625,7 @@ void ESP8266WebServer::_finalizeResponse() {
} }
} }
const String ESP8266WebServer::_responseCodeToString(int code) { const String ESP8266WebServer::responseCodeToString(const int code) {
switch (code) { switch (code) {
case 100: return F("Continue"); case 100: return F("Continue");
case 101: return F("Switching Protocols"); case 101: return F("Switching Protocols");

View File

@ -135,6 +135,8 @@ public:
return _currentClient.write(file); return _currentClient.write(file);
} }
static const String responseCodeToString(const int code);
protected: protected:
virtual size_t _currentClientWrite(const char* b, size_t l) { return _currentClient.write( b, l ); } virtual size_t _currentClientWrite(const char* b, size_t l) { return _currentClient.write( b, l ); }
virtual size_t _currentClientWrite_P(PGM_P b, size_t l) { return _currentClient.write_P( b, l ); } virtual size_t _currentClientWrite_P(PGM_P b, size_t l) { return _currentClient.write_P( b, l ); }
@ -144,7 +146,6 @@ protected:
bool _parseRequest(WiFiClient& client); bool _parseRequest(WiFiClient& client);
void _parseArguments(const String& data); void _parseArguments(const String& data);
int _parseArgumentsPrivate(const String& data, std::function<void(String&,String&,const String&,int,int,int,int)> handler); int _parseArgumentsPrivate(const String& data, std::function<void(String&,String&,const String&,int,int,int,int)> handler);
static const String _responseCodeToString(int code);
bool _parseForm(WiFiClient& client, const String& boundary, uint32_t len); bool _parseForm(WiFiClient& client, const String& boundary, uint32_t len);
bool _parseFormUploadAborted(); bool _parseFormUploadAborted();
void _uploadWriteByte(uint8_t b); void _uploadWriteByte(uint8_t b);