diff --git a/Makefile b/Makefile index 1b6fd96..d7a5f17 100644 --- a/Makefile +++ b/Makefile @@ -166,18 +166,17 @@ flash: $(TARGET_OUT) $(FW_BASE) $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x00000 $(FW_BASE)/0x00000.bin 0x40000 $(FW_BASE)/0x40000.bin webpages.espfs: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage -ifeq ($(GZIP_COMPRESSION),"yes") +ifeq ($(COMPRESS_W_YUI),"yes") $(Q) rm -rf html_compressed; $(Q) cp -r html html_compressed; -ifeq ($(COMPRESS_W_YUI),"yes") $(Q) echo "Compression assets with yui-compressor. This may take a while..." $(Q) for file in `find html_compressed -type f -name "*.js"`; do $(YUI-COMPRESSOR) --type js $$file -o $$file; done $(Q) for file in `find html_compressed -type f -name "*.css"`; do $(YUI-COMPRESSOR) --type css $$file -o $$file; done $(Q) awk "BEGIN {printf \"YUI compression ratio was: %.2f%%\\n\", (`du -b -s html_compressed/ | sed 's/\([0-9]*\).*/\1/'`/`du -b -s html/ | sed 's/\([0-9]*\).*/\1/'`)*100}" -endif - $(Q) cd html_compressed; find . -type f -regex ".*/.*\.\(html\|css\|js\)" -exec sh -c "gzip -n {}; mv {}.gz {}" \;; cd ..; + +# mkespfsimage will compress html, css and js files with gzip by default if enabled +# override with -g cmdline parameter $(Q) cd html_compressed; find | ../espfs/mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..; - $(Q) awk "BEGIN {printf \"GZIP compression ratio was: %.2f%%\\n\", (`du -b -s html_compressed/ | sed 's/\([0-9]*\).*/\1/'`/`du -b -s html/ | sed 's/\([0-9]*\).*/\1/'`)*100}" else $(Q) cd html; find | ../espfs/mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. endif @@ -196,7 +195,7 @@ clean: $(Q) make -C espfs/mkespfsimage/ clean $(Q) rm -rf $(FW_BASE) $(Q) rm -f webpages.espfs -ifeq ($(GZIP_COMPRESSION),"yes") +ifeq ($(COMPRESS_W_YUI),"yes") $(Q) rm -rf html_compressed endif diff --git a/httpd/httpd.c b/httpd/httpd.c index 36fcd8a..59c4d40 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -66,19 +66,6 @@ static const MimeMap mimeTypes[]={ {NULL, "text/html"}, //default value }; -// The static files with the following extensions from the HTML folder will be compressed and served with GZIP compression -// Add any other file types you want compressed here (and don't forget to modify the Makefile too) -#ifdef GZIP_COMPRESSION -static const char * gzippedFileTypes[] = { - "js", - "html", - "css", - NULL -}; - -static const char gzipNonSupportedMessage[] = "
Your browser does not accept gzip-compressed data."; -#endif - //Returns a static char* to a mime type for a given url to a file. const char ICACHE_FLASH_ATTR *httpdGetMimetype(char *url) { int i=0; @@ -92,39 +79,6 @@ const char ICACHE_FLASH_ATTR *httpdGetMimetype(char *url) { return mimeTypes[i].mimetype; } - -#ifdef GZIP_COMPRESSION -//Sends Content-encoding header if the requested file was GZIP compressed -//If the client does not sent the Accept-encoding, send out a static html message. -const char* sendGZIPEncodingIfNeeded(HttpdConnData *connData) { - int i=0; - char acceptEncodingBuffer[64]; - //Go find the extension - char *ext=connData->url+(strlen(connData->url)-1); - while (ext!=connData->url && *ext!='.') ext--; - if (*ext=='.') ext++; - - //ToDo: os_strcmp is case sensitive; we may want to do case-intensive matching here... - while (gzippedFileTypes[i]!=NULL) { - if (os_strcmp(ext, gzippedFileTypes[i])==0) { - //when serving gzipped files check the browser's "Accept-Encoding" header - //if the client does not advertises that he accepts GZIP send a warning message (telnet users for e.g.) - httpdGetHeader(connData, "Accept-Encoding", acceptEncodingBuffer, 64); - if (os_strstr(acceptEncodingBuffer, "gzip") == NULL) { - //No Accept-Encoding: gzip header present - return gzipNonSupportedMessage; - } else { - httpdHeader(connData, "Content-Encoding", "gzip"); - return NULL; - } - } - i++; - } - return NULL; -} -#endif - - //Looks up the connData info for a specific esp connection static HttpdConnData ICACHE_FLASH_ATTR *httpdFindConnData(void *arg) { int i; diff --git a/httpd/httpd.h b/httpd/httpd.h index 8ef6e72..95611bd 100644 --- a/httpd/httpd.h +++ b/httpd/httpd.h @@ -56,9 +56,6 @@ int httpdUrlDecode(char *val, int valLen, char *ret, int retLen); int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen); void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port); const char *httpdGetMimetype(char *url); -#ifdef GZIP_COMPRESSION -const char* sendGZIPEncodingIfNeeded(HttpdConnData *connData); -#endif void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code); void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val); void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn); diff --git a/httpd/httpdespfs.c b/httpd/httpdespfs.c index 2eeb90c..a182bb8 100644 --- a/httpd/httpdespfs.c +++ b/httpd/httpdespfs.c @@ -14,6 +14,11 @@ Connector to let httpd use the espfs filesystem to serve the files in it. #include