File tree 2 files changed +15
-3
lines changed
libraries/ESP8266WebServer/src
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -151,10 +151,22 @@ class ESP8266WebServerTemplate
151
151
152
152
static String urlDecode (const String& text);
153
153
154
+ // Handle a GET request by sending a response header and stream file content to response body
154
155
template <typename T>
155
156
size_t streamFile (T &file, const String& contentType) {
157
+ return streamFile (file, contentType, HTTP_GET);
158
+ }
159
+
160
+ // Implement GET and HEAD requests for files.
161
+ // Stream body on HTTP_GET but not on HTTP_HEAD requests.
162
+ template <typename T>
163
+ size_t streamFile (T &file, const String& contentType, HTTPMethod requestMethod) {
164
+ size_t contentLength = 0 ;
156
165
_streamFileCore (file.size (), file.name (), contentType);
157
- return _currentClient.write (file);
166
+ if (requestMethod == HTTP_GET) {
167
+ contentLength = _currentClient.write (file);
168
+ }
169
+ return contentLength;
158
170
}
159
171
160
172
static const String responseCodeToString (const int code);
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
76
76
}
77
77
78
78
bool canHandle (HTTPMethod requestMethod, String requestUri) override {
79
- if (requestMethod != HTTP_GET)
79
+ if (( requestMethod != HTTP_GET) && (requestMethod != HTTP_HEAD) )
80
80
return false ;
81
81
82
82
if ((_isFile && requestUri != _uri) || !requestUri.startsWith (_uri))
@@ -125,7 +125,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
125
125
if (_cache_header.length () != 0 )
126
126
server.sendHeader (" Cache-Control" , _cache_header);
127
127
128
- server.streamFile (f, contentType);
128
+ server.streamFile (f, contentType, requestMethod );
129
129
return true ;
130
130
}
131
131
You can’t perform that action at this time.
0 commit comments