From 77cd95b55232bf50e89a4d6650e9d02a8bf5adee Mon Sep 17 00:00:00 2001 From: hillsp Date: Wed, 11 May 2016 13:34:00 -0400 Subject: [PATCH] Fix IPRO and missing Content-Length headers in 32-bit builds. (#1196) --- src/ngx_base_fetch.cc | 14 +++++++++++--- src/ngx_pagespeed.cc | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ngx_base_fetch.cc b/src/ngx_base_fetch.cc index b112ce10d..7bfab2fc5 100644 --- a/src/ngx_base_fetch.cc +++ b/src/ngx_base_fetch.cc @@ -12,17 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Author: jefftk@google.com (Jeff Kaufman) */ -// Author: jefftk@google.com (Jeff Kaufman) +#include "ngx_pagespeed.h" // Must come first, see comments in CollectHeaders. + #include //for usleep #include "ngx_base_fetch.h" #include "ngx_event_connection.h" #include "ngx_list_iterator.h" -#include "ngx_pagespeed.h" - #include "net/instaweb/rewriter/public/rewrite_driver.h" #include "net/instaweb/rewriter/public/rewrite_options.h" #include "net/instaweb/rewriter/public/rewrite_stats.h" @@ -255,6 +256,13 @@ ngx_int_t NgxBaseFetch::CollectAccumulatedWrites(ngx_chain_t** link_ptr) { } ngx_int_t NgxBaseFetch::CollectHeaders(ngx_http_headers_out_t* headers_out) { + // nginx defines _FILE_OFFSET_BITS to 64, which changes the size of off_t. + // If a standard header is accidentally included before the nginx header, + // on a 32-bit system off_t will be 4 bytes and we don't assign all the + // bits of content_length_n. Sanity check that did not happen. + // This could use static_assert, but this file is not built with --std=c++11. + bool sanity_check_off_t[sizeof(off_t) == 8 ? 1 : -1] __attribute__ ((unused)); + const ResponseHeaders* pagespeed_headers = response_headers(); if (content_length_known()) { diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc index dde5be8e0..9508e9875 100644 --- a/src/ngx_pagespeed.cc +++ b/src/ngx_pagespeed.cc @@ -492,7 +492,8 @@ void copy_response_headers_from_ngx(const ngx_http_request_t* r, // When we don't have a date header, set one with the current time. if (headers->Lookup1(HttpAttributes::kDate) == NULL) { - headers->SetDate(ngx_current_msec); + PosixTimer timer; + headers->SetDate(timer.NowMs()); } // TODO(oschaaf): ComputeCaching should be called in setupforhtml()?