+/**
+ * Proxies thumbnail request to a service that handles thumbnailing
+ *
+ * @param File $img
+ * @param string $thumbName
+ */
+function wfProxyThumbnailRequest( $img, $thumbName ) {
+ $thumbProxyUrl = $img->getRepo()->getThumbProxyUrl();
+
+ // Instead of generating the thumbnail ourselves, we proxy the request to another service
+ $thumbProxiedUrl = $thumbProxyUrl . $img->getThumbRel( $thumbName );
+
+ $req = MWHttpRequest::factory( $thumbProxiedUrl );
+ $secret = $img->getRepo()->getThumbProxySecret();
+
+ // Pass a secret key shared with the proxied service if any
+ if ( strlen( $secret ) ) {
+ $req->setHeader( 'X-Swift-Secret', $secret );
+ }
+
+ // Send request to proxied service
+ $status = $req->execute();
+
+ // Simply serve the response from the proxied service as-is
+ header( 'HTTP/1.1 ' . $req->getStatus() );
+
+ $headers = $req->getResponseHeaders();
+
+ foreach ( $headers as $key => $values ) {
+ foreach ( $values as $value ) {
+ header( $key . ': ' . $value, false );
+ }
+ }
+
+ echo $req->getContent();
+}
+