Index: trunk/phase3/includes/OutputHandler.php |
— | — | @@ -18,30 +18,67 @@ |
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
| 22 | + * Get the "file extension" that some client apps will estimate from |
| 23 | + * the currently-requested URL. |
| 24 | + * This isn't on WebRequest because we need it when things aren't initialized |
| 25 | + * @private |
| 26 | + */ |
| 27 | +function wfRequestExtension() { |
| 28 | + /// @fixme -- this sort of dupes some code in WebRequest::getRequestUrl() |
| 29 | + if( isset( $_SERVER['REQUEST_URI'] ) ) { |
| 30 | + // Strip the query string... |
| 31 | + list( $path ) = explode( '?', $_SERVER['REQUEST_URI'], 2 ); |
| 32 | + } elseif( isset( $_SERVER['SCRIPT_NAME'] ) ) { |
| 33 | + // Probably IIS. QUERY_STRING appears separately. |
| 34 | + $path = $_SERVER['SCRIPT_NAME']; |
| 35 | + } else { |
| 36 | + // Can't get the path from the server? :( |
| 37 | + return ''; |
| 38 | + } |
| 39 | + |
| 40 | + $period = strrpos( $path, '.' ); |
| 41 | + if( $period !== false ) { |
| 42 | + return strtolower( substr( $path, $period ) ); |
| 43 | + } |
| 44 | + return ''; |
| 45 | +} |
| 46 | + |
| 47 | +/** |
22 | 48 | * Handler that compresses data with gzip if allowed by the Accept header. |
23 | 49 | * Unlike ob_gzhandler, it works for HEAD requests too. |
24 | 50 | */ |
25 | 51 | function wfGzipHandler( $s ) { |
26 | | - if ( function_exists( 'gzencode' ) && !headers_sent() ) { |
27 | | - $tokens = preg_split( '/[,; ]/', $_SERVER['HTTP_ACCEPT_ENCODING'] ); |
28 | | - if ( in_array( 'gzip', $tokens ) ) { |
29 | | - header( 'Content-Encoding: gzip' ); |
30 | | - $s = gzencode( $s, 3 ); |
31 | | - |
32 | | - # Set vary header if it hasn't been set already |
33 | | - $headers = headers_list(); |
34 | | - $foundVary = false; |
35 | | - foreach ( $headers as $header ) { |
36 | | - if ( substr( $header, 0, 5 ) == 'Vary:' ) { |
37 | | - $foundVary = true; |
38 | | - break; |
39 | | - } |
40 | | - } |
41 | | - if ( !$foundVary ) { |
42 | | - header( 'Vary: Accept-Encoding' ); |
43 | | - } |
| 52 | + if( !function_exists( 'gzencode' ) || headers_sent() ) { |
| 53 | + return $s; |
| 54 | + } |
| 55 | + |
| 56 | + $ext = wfRequestExtension(); |
| 57 | + if( $ext == '.gz' || $ext == '.tgz' ) { |
| 58 | + // Don't do gzip compression if the URL path ends in .gz or .tgz |
| 59 | + // This confuses Safari and triggers a download of the page, |
| 60 | + // even though it's pretty clearly labeled as viewable HTML. |
| 61 | + // Bad Safari! Bad! |
| 62 | + return $s; |
| 63 | + } |
| 64 | + |
| 65 | + $tokens = preg_split( '/[,; ]/', $_SERVER['HTTP_ACCEPT_ENCODING'] ); |
| 66 | + if ( in_array( 'gzip', $tokens ) ) { |
| 67 | + header( 'Content-Encoding: gzip' ); |
| 68 | + $s = gzencode( $s, 3 ); |
| 69 | + } |
| 70 | + |
| 71 | + // Set vary header if it hasn't been set already |
| 72 | + $headers = headers_list(); |
| 73 | + $foundVary = false; |
| 74 | + foreach ( $headers as $header ) { |
| 75 | + if ( substr( $header, 0, 5 ) == 'Vary:' ) { |
| 76 | + $foundVary = true; |
| 77 | + break; |
44 | 78 | } |
45 | 79 | } |
| 80 | + if ( !$foundVary ) { |
| 81 | + header( 'Vary: Accept-Encoding' ); |
| 82 | + } |
46 | 83 | return $s; |
47 | 84 | } |
48 | 85 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -315,6 +315,7 @@ |
316 | 316 | * Fix several JavaScript bugs under MSIE 5/Macintosh |
317 | 317 | * (bug 10591) Use Arabic numerals (0,1,2...) for the Malayam language |
318 | 318 | * (bug 10642) Fix shift-click checkbox behavior for Opera 9.0+ and 6.0 |
| 319 | +* Work around Safari bug with pages ending in ".gz" or ".tgz" |
319 | 320 | |
320 | 321 | |
321 | 322 | == API changes since 1.10 == |