Fixed headers sent in addMissingMetadata()
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 22 Jul 2015 21:26:31 +0000 (14:26 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 5 Aug 2015 08:46:52 +0000 (01:46 -0700)
* This used to relay back *all* of the GET headers, which includes
  things that are not changeable (Content-Length) or make no sense
  (x-trans-id). Only send the actual HTTP/metadata headers. Oddly
  enough sending garbage headers gives a 2XX response, but does
  not actually change anything in Swift.

Bug: T105810
Change-Id: Id4829cf998a6d8763fd26d49cd8d9c16cf5527dd

includes/filebackend/SwiftFileBackend.php

index 6a0f2ee..3d089df 100644 (file)
@@ -716,6 +716,11 @@ class SwiftFileBackend extends FileBackendStore {
                        return $objHdrs; // failed
                }
 
+               // Find prior custom HTTP headers
+               $postHeaders = $this->getCustomHeaders( $objHdrs );
+               // Find prior metadata headers
+               $postHeaders += $this->getMetadataHeaders( $objHdrs );
+
                $status = Status::newGood();
                /** @noinspection PhpUnusedLocalVariableInspection */
                $scopeLockS = $this->getScopedFileLocks( array( $path ), LockManager::LOCK_UW, $status );
@@ -725,11 +730,13 @@ class SwiftFileBackend extends FileBackendStore {
                                $hash = $tmpFile->getSha1Base36();
                                if ( $hash !== false ) {
                                        $objHdrs['x-object-meta-sha1base36'] = $hash;
+                                       // Merge new SHA1 header into the old ones
+                                       $postHeaders['x-object-meta-sha1base36'] = $hash;
                                        list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $path );
-                                       list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->http->run( array(
+                                       list( $rcode ) = $this->http->run( array(
                                                'method' => 'POST',
                                                'url' => $this->storageUrl( $auth, $srcCont, $srcRel ),
-                                               'headers' => $this->authTokenHeaders( $auth ) + $objHdrs
+                                               'headers' => $this->authTokenHeaders( $auth ) + $postHeaders
                                        ) );
                                        if ( $rcode >= 200 && $rcode <= 299 ) {
                                                $this->deleteFileCache( $path );