Seek to the start of the file when calculating the ETag.
@@ -155,7 +155,7 @@ AP_DECLARE(char *) ap_make_etag_ex(request_rec *r, etag_rec *er)
apr_file_t *fd = NULL;
apr_size_t nbytes;
- apr_off_t offset = 0;
+ apr_off_t offset = 0, zero = 0;
apr_status_t status;
if (er->fd) {
@@ -185,6 +185,15 @@ AP_DECLARE(char *) ap_make_etag_ex(request_rec *r, etag_rec *er)
return "";
}
+ if ((status = apr_file_seek(fd, APR_SET, &zero)) != APR_SUCCESS) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO()
+ "Make etag: could not seek");
+ if (er->pathname) {
+ apr_file_close(fd);
+ }
+ return "";
+ }
+
apr_sha1_init(&context);
nbytes = sizeof(buf);
while ((status = apr_file_read(fd, buf, &nbytes)) == APR_SUCCESS) {
