@ -14,6 +14,11 @@ Connector to let httpd use the espfs filesystem to serve the files in it.
#include<esp8266.h>
#include"httpdespfs.h"
#include"espfs.h"
#include"espfsformat.h"
// The static files marked with FLAG_GZIP are compressed and will be served with GZIP compression.
// If the client does not advertise that he accepts GZIP send following warning message (telnet users for e.g.)
staticconstchar*gzipNonSupportedMessage="HTTP/1.0 501 Not implemented\r\nServer: esp8266-httpd/"HTTPDVER"\r\nContent-Type: text/plain\r\nContent-Length: 52\r\n\r\nYour browser does not accept gzip-compressed data.\r\n";
//This is a catch-all cgi function. It takes the url passed to it, looks up the corresponding
@ -23,9 +28,8 @@ int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData) {
EspFsFile*file=connData->cgiData;
intlen;
charbuff[1024];
#ifdef GZIP_COMPRESSION
constchar*gzipSendResult=NULL;
#endif
characceptEncodingBuffer[64];
intisGzip;
if(connData->conn==NULL){
//Connection aborted. Clean up.
@ -39,17 +43,32 @@ int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData) {
if(file==NULL){
returnHTTPD_CGI_NOTFOUND;
}
// The gzip checking code is intentionally without #ifdefs because checking
// for FLAG_GZIP (which indicates gzip compressed file) is very easy, doesn't
// mean additional overhead and is actually safer to be on at all times.
// If there are no gzipped files in the image, the code bellow will not cause any harm.
// Check if requested file was GZIP compressed
isGzip=espFsFlags(file)&FLAG_GZIP;
if(isGzip){
// Check the browser's "Accept-Encoding" header. If the client does not
// advertise that he accepts GZIP send a warning message (telnet users for e.g.)