diff --git a/networking/httpd.c b/networking/httpd.c index 9439e206c..b52526a78 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -392,7 +392,10 @@ static const struct { struct globals { int verbose; /* must be int (used by getopt32) */ smallint flg_deny_all; - +#if ENABLE_FEATURE_HTTPD_GZIP + /* client can handle gzip / we are going to send gzip */ + smallint content_gzip; +#endif unsigned rmt_ip; /* used for IP-based allow/deny rules */ time_t last_mod; char *rmt_ip_str; /* for $REMOTE_ADDR and $REMOTE_PORT */ @@ -440,14 +443,15 @@ struct globals { #if ENABLE_FEATURE_HTTPD_PROXY Htaccess_Proxy *proxy; #endif -#if ENABLE_FEATURE_HTTPD_GZIP - /* client can handle gzip / we are going to send gzip */ - smallint content_gzip; -#endif }; #define G (*ptr_to_globals) #define verbose (G.verbose ) #define flg_deny_all (G.flg_deny_all ) +#if ENABLE_FEATURE_HTTPD_GZIP +# define content_gzip (G.content_gzip ) +#else +# define content_gzip 0 +#endif #define rmt_ip (G.rmt_ip ) #define bind_addr_or_port (G.bind_addr_or_port) #define g_query (G.g_query ) @@ -481,11 +485,6 @@ enum { #define hdr_cnt (G.hdr_cnt ) #define http_error_page (G.http_error_page ) #define proxy (G.proxy ) -#if ENABLE_FEATURE_HTTPD_GZIP -# define content_gzip (G.content_gzip ) -#else -# define content_gzip 0 -#endif #define INIT_G() do { \ setup_common_bufsiz(); \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ @@ -944,7 +943,7 @@ static char *encodeString(const char *string) if (isalnum(ch)) *p++ = ch; else - p += sprintf(p, "%d;", (unsigned char) ch); + p += sprintf(p, "%u;", (unsigned char) ch); } *p = '\0'; return out; @@ -1040,7 +1039,7 @@ static void log_and_exit(void) * second packet is delayed for any reason. * responseNum - the result code to send. */ -static void send_headers(int responseNum) +static void send_headers(unsigned responseNum) { static const char RFC1123FMT[] ALIGN1 = "%a, %d %b %Y %H:%M:%S GMT"; /* Fixed size 29-byte string. Example: Sun, 06 Nov 1994 08:49:37 GMT */ @@ -1052,9 +1051,9 @@ static void send_headers(int responseNum) #if ENABLE_FEATURE_HTTPD_ERROR_PAGES const char *error_page = NULL; #endif + unsigned len; unsigned i; time_t timer = time(NULL); - int len; for (i = 0; i < ARRAY_SIZE(http_response_type); i++) { if (http_response_type[i] == responseNum) { @@ -1078,16 +1077,21 @@ static void send_headers(int responseNum) strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm)); /* ^^^ using gmtime_r() instead of gmtime() to not use static data */ len = sprintf(iobuf, - "HTTP/1.0 %d %s\r\n" - "Content-type: %s\r\n" + "HTTP/1.0 %u %s\r\n" "Date: %s\r\n" "Connection: close\r\n", responseNum, responseString, - /* if it's error message, then it's HTML */ - (responseNum == HTTP_OK ? found_mime_type : "text/html"), date_str ); + if (responseNum != HTTP_OK || found_mime_type) { + len += sprintf(iobuf + len, + "Content-type: %s\r\n", + /* if it's error message, then it's HTML */ + (responseNum != HTTP_OK ? "text/html" : found_mime_type) + ); + } + #if ENABLE_FEATURE_HTTPD_BASIC_AUTH if (responseNum == HTTP_UNAUTHORIZED) { len += sprintf(iobuf + len, @@ -1147,9 +1151,9 @@ static void send_headers(int responseNum) "Accept-Ranges: bytes\r\n" #endif "Last-Modified: %s\r\n" - "%s %"OFF_FMT"u\r\n", + "%s-Length: %"OFF_FMT"u\r\n", date_str, - content_gzip ? "Transfer-Length:" : "Content-Length:", + content_gzip ? "Transfer" : "Content", file_size ); } @@ -1161,8 +1165,8 @@ static void send_headers(int responseNum) iobuf[len++] = '\n'; if (infoString) { len += sprintf(iobuf + len, - "