← Commit list

b720629df

Denys Vlasenko
Denys Vlasenko
2021-12-17
SUCCESS Duration: 154s

Subject

httpd: do not send Last-Modified / ETag / Content-Length for error pages

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

networking/httpd.c+14 -20
@@ -1222,29 +1222,17 @@ static void send_headers(unsigned responseNum)
// (NB: standards do not define "Transfer-Length:" _header_,
// transfer-length above is just a concept).
-#if ENABLE_FEATURE_HTTPD_RANGES \
- || ENABLE_FEATURE_HTTPD_LAST_MODIFIED \
- || ENABLE_FEATURE_HTTPD_ETAG
len += sprintf(iobuf + len,
-# if ENABLE_FEATURE_HTTPD_RANGES
+#if ENABLE_FEATURE_HTTPD_RANGES
"Accept-Ranges: bytes\r\n"
-# endif
-# if ENABLE_FEATURE_HTTPD_LAST_MODIFIED
+#endif
+#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED
"Last-Modified: %s\r\n"
-# endif
-# if ENABLE_FEATURE_HTTPD_ETAG
+#endif
+#if ENABLE_FEATURE_HTTPD_ETAG
"ETag: %s\r\n"
-# endif
-# if ENABLE_FEATURE_HTTPD_LAST_MODIFIED
- , date_str
-# endif
-# if ENABLE_FEATURE_HTTPD_ETAG
- , G.etag
-# endif
#endif
- );
- if (!infoString) {
- len += sprintf(iobuf + len,
+
/* Because of 4.4 (5), we can forgo sending of "Content-Length"
* since we close connection afterwards, but it helps clients
* to e.g. estimate download times, show progress bars etc.
@@ -1252,9 +1240,14 @@ static void send_headers(unsigned responseNum)
* but de-facto standard is to send it (see comment below).
*/
"Content-Length: %"OFF_FMT"u\r\n",
+#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED
+ date_str,
+#endif
+#if ENABLE_FEATURE_HTTPD_ETAG
+ G.etag,
+#endif
file_size
- );
- }
+ );
}
/* This should be "Transfer-Encoding", not "Content-Encoding":
@@ -1297,6 +1290,7 @@ static void send_headers_and_exit(int responseNum) NORETURN;
static void send_headers_and_exit(int responseNum)
{
IF_FEATURE_HTTPD_GZIP(content_gzip = 0;)
+ file_size = -1; /* no Last-Modified:, ETag:, Content-Length: */
send_headers(responseNum);
log_and_exit();
}