diff options
-rw-r--r-- | networking/httpd.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 2b0acd7dc..0f4f22669 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1150,18 +1150,61 @@ static void send_headers(unsigned responseNum) | |||
1150 | file_size = range_end - range_start + 1; | 1150 | file_size = range_end - range_start + 1; |
1151 | } | 1151 | } |
1152 | #endif | 1152 | #endif |
1153 | |||
1154 | //RFC 2616 4.4 Message Length | ||
1155 | // The transfer-length of a message is the length of the message-body as | ||
1156 | // it appears in the message; that is, after any transfer-codings have | ||
1157 | // been applied. When a message-body is included with a message, the | ||
1158 | // transfer-length of that body is determined by one of the following | ||
1159 | // (in order of precedence): | ||
1160 | // 1.Any response message which "MUST NOT" include a message-body (such | ||
1161 | // as the 1xx, 204, and 304 responses and any response to a HEAD | ||
1162 | // request) is always terminated by the first empty line after the | ||
1163 | // header fields, regardless of the entity-header fields present in | ||
1164 | // the message. | ||
1165 | // 2.If a Transfer-Encoding header field (section 14.41) is present and | ||
1166 | // has any value other than "identity", then the transfer-length is | ||
1167 | // defined by use of the "chunked" transfer-coding (section 3.6), | ||
1168 | // unless the message is terminated by closing the connection. | ||
1169 | // 3.If a Content-Length header field (section 14.13) is present, its | ||
1170 | // decimal value in OCTETs represents both the entity-length and the | ||
1171 | // transfer-length. The Content-Length header field MUST NOT be sent | ||
1172 | // if these two lengths are different (i.e., if a Transfer-Encoding | ||
1173 | // header field is present). If a message is received with both a | ||
1174 | // Transfer-Encoding header field and a Content-Length header field, | ||
1175 | // the latter MUST be ignored. | ||
1176 | // 4.If the message uses the media type "multipart/byteranges" ... | ||
1177 | // 5.By the server closing the connection. | ||
1178 | // | ||
1179 | // (NB: standards do not define "Transfer-Length:" _header_, | ||
1180 | // transfer-length above is just a concept). | ||
1181 | |||
1153 | len += sprintf(iobuf + len, | 1182 | len += sprintf(iobuf + len, |
1154 | #if ENABLE_FEATURE_HTTPD_RANGES | 1183 | #if ENABLE_FEATURE_HTTPD_RANGES |
1155 | "Accept-Ranges: bytes\r\n" | 1184 | "Accept-Ranges: bytes\r\n" |
1156 | #endif | 1185 | #endif |
1157 | "Last-Modified: %s\r\n" | 1186 | "Last-Modified: %s\r\n" |
1158 | "%s-Length: %"OFF_FMT"u\r\n", | 1187 | /* Because of 4.4 (5), we can forgo sending of "Content-Length" |
1188 | * since we close connection afterwards, but it helps clients | ||
1189 | * to e.g. estimate download times, show progress bars etc. | ||
1190 | * Theoretically we should not send it if page is compressed, | ||
1191 | * but de-facto standard is to send it (see comment below). | ||
1192 | */ | ||
1193 | "Content-Length: %"OFF_FMT"u\r\n", | ||
1159 | date_str, | 1194 | date_str, |
1160 | content_gzip ? "Transfer" : "Content", | ||
1161 | file_size | 1195 | file_size |
1162 | ); | 1196 | ); |
1163 | } | 1197 | } |
1164 | 1198 | ||
1199 | /* This should be "Transfer-Encoding", not "Content-Encoding": | ||
1200 | * "data is compressed for transfer", not "data is an archive". | ||
1201 | * But many clients were not handling "Transfer-Encoding" correctly | ||
1202 | * (they were not uncompressing gzipped pages, tried to show | ||
1203 | * raw compressed data), and servers worked around it by using | ||
1204 | * "Content-Encoding" instead... and this become de-facto standard. | ||
1205 | * https://bugzilla.mozilla.org/show_bug.cgi?id=68517 | ||
1206 | * https://bugs.chromium.org/p/chromium/issues/detail?id=94730 | ||
1207 | */ | ||
1165 | if (content_gzip) | 1208 | if (content_gzip) |
1166 | len += sprintf(iobuf + len, "Content-Encoding: gzip\r\n"); | 1209 | len += sprintf(iobuf + len, "Content-Encoding: gzip\r\n"); |
1167 | 1210 | ||