-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebServer / StaticRequestHandler with mixed gz and non-gz contents #10824
Comments
This is on purpose. The point is to be able to edit the HTML and when you are happy to turn it into gzip. Legacy from the FSBrowser. Firmware comes with some standard gzipped index and you can add your own uncompressed one through the editor/upload |
This logic only makes sense with FSBrowser. and it breaks the principles of content negociation (should use the "best-suited" method in every situation). |
I guess you are proposing to parse the Accept-Encoding header, as well as returning the GZIP by default (if present)? |
yup, I'm not sure how to do that without affecting the FSBrowser editing workflow though that's what I'm using in a custom handler, I also have to add bool hasGz = false;
if( server.hasHeader("Accept-Encoding") ) {
String acceptEncoding = server.header("Accept-Encoding");
if( acceptEncoding.indexOf("gzip") > 0 || acceptEncoding.indexOf("deflate") > 0 ) {
hasGz = _fs.exists(pathWithGz);
}
}
if( hasGz ) {
path = pathWithGz;
}
|
Adding more feedback here as I found another anomaly in WebServer class:
arduino-esp32/libraries/WebServer/src/WebServer.cpp Lines 564 to 569 in 2f423af
While this is correct with HTTP 1.1, it isn't valid with HTTP 1.0. With HTTP 1.0 the Content-Length header is optional: chunked transfer encoding is only available since HTTP 1.1. |
we can not support requests with unknown lengths in HTTP1.0. Either send the length with 1.0 or use chunked with 1.1 |
This is implicit in both HTTP/1.0 and HTTP/1.1: a server response without content-length ends when the stream closes. https://datatracker.ietf.org/doc/html/rfc1945#section-7.2.2
Moreover, a HTTP/1.1 response without content-length is not necessarily chunked, it can be multipart/byteranges or support other (!=identity) transfer encodings. https://datatracker.ietf.org/doc/html/rfc2616#section-4.4
|
Seems you have done quite a bit of research. Why not make a PR with the changes? |
Because I'm biased by my use case (to mimic apache's mod_gzip+mod_cache) and therefore at risk of bloating the library with maybe-unnecessary features. In my use case, skipping the content-length header only makes sense when streaming content of unknown size generated on the fly (such as gzip/deflate), so I overloaded/inherited instead of modifying the WebServer library:
I need study that new middleware class anyway, I haven't figured out yet if it should be involded. |
Board
any
Device Description
any esp32 device
Hardware Configuration
any configuration using WebServer library
Version
3.1.0 (also on master)
IDE Name
Arduino IDE (any)
Operating System
Linux
Flash frequency
n/a
PSRAM enabled
yes
Upload speed
n/a
Description
Currentl StaticRequestHandler doesn't serve
index.htm.gz
file whenindex.htm
exists.&& !_fs.exists(path)
prevents gz content to be served: when both compressed and uncompressed versions of same file are present, the uncompressed version is served.arduino-esp32/libraries/WebServer/src/detail/RequestHandlersImpl.h
Line 207 in 51ef2a1
Moreover,
StaticRequestHandler::handle()
completely ignores the 'Accept-Encoding' header sent by the client, which should be checked forgzip
and/ordeflate
before deciding if it is worth looking for a compressed version of the file.Sketch
Debug Message
filesystem contents:
current behaviour:
expected behaviour:
other expected behaviour (no accept-encoding headers):
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: