Merge "Improve MIME detection in FileBackend"
[lhc/web/wiklou.git] / includes / filebackend / FileBackendStore.php
index 8113ec2..1432bb9 100644 (file)
@@ -1063,7 +1063,7 @@ abstract class FileBackendStore extends FileBackend {
                $status = Status::newGood();
 
                // Fix up custom header name/value pairs...
-               $ops = array_map( array( $this, 'stripInvalidHeadersFromOp' ), $ops );
+               $ops = array_map( array( $this, 'sanitizeOpHeaders' ), $ops );
 
                // Build up a list of FileOps...
                $performOps = $this->getOperationsInternal( $ops );
@@ -1130,7 +1130,7 @@ abstract class FileBackendStore extends FileBackend {
                $status = Status::newGood();
 
                // Fix up custom header name/value pairs...
-               $ops = array_map( array( $this, 'stripInvalidHeadersFromOp' ), $ops );
+               $ops = array_map( array( $this, 'sanitizeOpHeaders' ), $ops );
 
                // Clear any file cache entries
                $this->clearCache();
@@ -1227,7 +1227,9 @@ abstract class FileBackendStore extends FileBackend {
        }
 
        /**
-        * Strip long HTTP headers from a file operation.
+        * Normalize and filter HTTP headers from a file operation
+        *
+        * This normalizes and strips long HTTP headers from a file operation.
         * Most headers are just numbers, but some are allowed to be long.
         * This function is useful for cleaning up headers and avoiding backend
         * specific errors, especially in the middle of batch file operations.
@@ -1235,18 +1237,21 @@ abstract class FileBackendStore extends FileBackend {
         * @param array $op Same format as doOperation()
         * @return array
         */
-       protected function stripInvalidHeadersFromOp( array $op ) {
-               static $longs = array( 'Content-Disposition' );
+       protected function sanitizeOpHeaders( array $op ) {
+               static $longs = array( 'content-disposition' );
+
                if ( isset( $op['headers'] ) ) { // op sets HTTP headers
+                       $newHeaders = array();
                        foreach ( $op['headers'] as $name => $value ) {
+                               $name = strtolower( $name );
                                $maxHVLen = in_array( $name, $longs ) ? INF : 255;
                                if ( strlen( $name ) > 255 || strlen( $value ) > $maxHVLen ) {
                                        trigger_error( "Header '$name: $value' is too long." );
-                                       unset( $op['headers'][$name] );
-                               } elseif ( !strlen( $value ) ) {
-                                       $op['headers'][$name] = ''; // null/false => ""
+                               } else {
+                                       $newHeaders[$name] = strlen( $value ) ? $value : ''; // null/false => ""
                                }
                        }
+                       $op['headers'] = $newHeaders;
                }
 
                return $op;