Skip to content

Commit 2528013

Browse files
authored
small addons (#5847)
* make (static) ESP8266WebServer::responseCodeToString visible and usable * esp8266:coreVersionNumeric(): add a define and comment-example to check on its usability
1 parent b1da9ed commit 2528013

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

cores/esp8266/core_esp8266_version.h

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#ifndef __CORE_ESP8266_VERSION_H
2323
#define __CORE_ESP8266_VERSION_H
2424

25+
#define HAS_ESP8266_VERSION_NUMERIC 1
26+
2527
#include <core_version.h>
2628

2729
#define __STRHELPER(x) #x
@@ -52,6 +54,20 @@ extern "C++"
5254
// esp8266CoreVersionSubRevision() is 3 Numeric is: 20499903
5355
// case 2.5.0:
5456
// esp8266CoreVersionSubRevision() is 0 Numeric is: 20500000
57+
//
58+
// Using esp8266::coreVersionNumeric() in a portable way:
59+
//
60+
// #if HAS_ESP8266_VERSION_NUMERIC
61+
// if (esp8266::coreVersionNumeric() >= 20500042)
62+
// {
63+
// // modern api can be used
64+
// }
65+
// else
66+
// #endif
67+
// {
68+
// // code using older api
69+
// // (will not be compiled in when newer api is usable)
70+
// }
5571

5672
namespace conststr {
5773

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ void ESP8266WebServer::_prepareHeader(String& response, int code, const char* co
371371
response = String(F("HTTP/1.")) + String(_currentVersion) + ' ';
372372
response += String(code);
373373
response += ' ';
374-
response += _responseCodeToString(code);
374+
response += responseCodeToString(code);
375375
response += "\r\n";
376376

377377
using namespace mime;
@@ -625,7 +625,7 @@ void ESP8266WebServer::_finalizeResponse() {
625625
}
626626
}
627627

628-
const String ESP8266WebServer::_responseCodeToString(int code) {
628+
const String ESP8266WebServer::responseCodeToString(const int code) {
629629
switch (code) {
630630
case 100: return F("Continue");
631631
case 101: return F("Switching Protocols");

libraries/ESP8266WebServer/src/ESP8266WebServer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class ESP8266WebServer
135135
return _currentClient.write(file);
136136
}
137137

138+
static const String responseCodeToString(const int code);
139+
138140
protected:
139141
virtual size_t _currentClientWrite(const char* b, size_t l) { return _currentClient.write( b, l ); }
140142
virtual size_t _currentClientWrite_P(PGM_P b, size_t l) { return _currentClient.write_P( b, l ); }
@@ -144,7 +146,6 @@ class ESP8266WebServer
144146
bool _parseRequest(WiFiClient& client);
145147
void _parseArguments(const String& data);
146148
int _parseArgumentsPrivate(const String& data, std::function<void(String&,String&,const String&,int,int,int,int)> handler);
147-
static const String _responseCodeToString(int code);
148149
bool _parseForm(WiFiClient& client, const String& boundary, uint32_t len);
149150
bool _parseFormUploadAborted();
150151
void _uploadWriteByte(uint8_t b);

0 commit comments

Comments
 (0)