Skip to content

Commit 0dbb04e

Browse files
ZakCodesearlephilhower
authored andcommitted
Add HTTP_HEAD to HTTPMethod and parse it (#6413)
* Add HTTP_HEAD to HTTPMethod * Parse the HTTP_HEAD variant of HTTPMethod from a method string * Add HTTP_HEAD to the ESP8266WebServer constants * Skip sending the content of the response if the HTTP method is HEAD method * Convert the HTTP status code 418 to string This status code is an easter egg from the IETF and is described in [RFC2324](https://tools.ietf.org/html/rfc2324#section-2.3.2)
1 parent 8f45a0f commit 0dbb04e

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

libraries/ESP8266WebServer/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ hostHeader KEYWORD2
4242
#######################################
4343

4444
HTTP_GET LITERAL1
45+
HTTP_HEAD LITERAL1
4546
HTTP_POST LITERAL1
4647
HTTP_ANY LITERAL1
4748
CONTENT_LENGTH_UNKNOWN LITERAL1

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

+2
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ void ESP8266WebServerTemplate<ServerType>::send(int code, const String& content_
480480

481481
template <typename ServerType>
482482
void ESP8266WebServerTemplate<ServerType>::sendContent(const String& content) {
483+
if (_currentMethod == HTTP_HEAD) return;
483484
const char * footer = "\r\n";
484485
size_t len = content.length();
485486
if(_chunked) {
@@ -728,6 +729,7 @@ const String ESP8266WebServerTemplate<ServerType>::responseCodeToString(const in
728729
case 415: return F("Unsupported Media Type");
729730
case 416: return F("Requested range not satisfiable");
730731
case 417: return F("Expectation Failed");
732+
case 418: return F("I'm a teapot");
731733
case 500: return F("Internal Server Error");
732734
case 501: return F("Not Implemented");
733735
case 502: return F("Bad Gateway");

libraries/ESP8266WebServer/src/ESP8266WebServer.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <FS.h>
3131
#include "detail/mimetable.h"
3232

33-
enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
33+
enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
3434
enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END,
3535
UPLOAD_FILE_ABORTED };
3636
enum HTTPClientStatus { HC_NONE, HC_WAIT_READ, HC_WAIT_CLOSE };
@@ -194,10 +194,10 @@ class ESP8266WebServerTemplate
194194
std::unique_ptr<HTTPUpload> _currentUpload;
195195
int _postArgsLen;
196196
RequestArgument* _postArgs;
197-
197+
198198
int _headerKeysCount;
199199
RequestArgument* _currentHeaders;
200-
200+
201201
size_t _contentLength;
202202
String _responseHeaders;
203203

libraries/ESP8266WebServer/src/Parsing-impl.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
9999
_chunked = false;
100100

101101
HTTPMethod method = HTTP_GET;
102-
if (methodStr == F("POST")) {
102+
if (methodStr == F("HEAD")) {
103+
method = HTTP_HEAD;
104+
} else if (methodStr == F("POST")) {
103105
method = HTTP_POST;
104106
} else if (methodStr == F("DELETE")) {
105107
method = HTTP_DELETE;

0 commit comments

Comments
 (0)