Skip to content

Instantly share code, notes, and snippets.

@phindmarsh
Created October 5, 2012 08:26
Show Gist options
  • Save phindmarsh/3838745 to your computer and use it in GitHub Desktop.
Save phindmarsh/3838745 to your computer and use it in GitHub Desktop.
Photon Patch
@@ -527,20 +527,26 @@ function photon_cache_headers( $expires=63115200 ) {
$image = new Gmagick();
-$parsed = parse_url( $_SERVER['REQUEST_URI'] );
+$parsed = parse_url( substr($_SERVER['REQUEST_URI'], 1) );
$exploded = explode( '/', $_SERVER['REQUEST_URI'] );
$origin_domain = strtolower( $exploded[1] );
$origin_domain_exception = array_key_exists( $origin_domain, $origin_domain_exceptions ) ? $origin_domain_exceptions[$origin_domain] : 0;
+$host = "";
+$path = $parsed['path'];
+if(isset($parsed['port'])){
+ $host = "{$parsed['host']}:{$parsed['port']}";
+}
+
$scheme = 'http' . ( array_key_exists( 'ssl', $_GET ) ? 's' : '' ) . '://';
parse_str( ( empty( $parsed['query'] ) ? '' : $parsed['query'] ), $_GET );
-$ext = strtolower( pathinfo( $parsed['path'], PATHINFO_EXTENSION ) );
+$ext = strtolower( pathinfo( $path, PATHINFO_EXTENSION ) );
if ( ! in_array( $ext, $allowed_types ) && !( $origin_domain_exception & PHOTON__ALLOW_ANY_EXTENSION ) )
httpdie( '400 Bad Request', 'The type of image you are trying to process is not allowed' );
-$url = $scheme . substr( $parsed['path'], 1 );
+$url = $scheme . $host . $path;
$url = preg_replace( '/#.*$/', '', $url );
$url = apply_filters( 'url', $url );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment