Skip to content

Commit 4cef435

Browse files
author
Tai Lee
committed
Rewrite Location response header, so clients will use the proxy for redirects.
1 parent fc6064e commit 4cef435

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

proxy.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@
106106

107107
// (re-)send the headers
108108
$response_headers = preg_split( '/(\r\n){1}/', $response_headers );
109-
foreach ( $response_headers as $key => $response_header )
110-
if ( !preg_match( '/^(Transfer-Encoding):/', $response_header ) )
109+
foreach ( $response_headers as $key => $response_header ) {
110+
// Rewrite the `Location` header, so clients will also use the proxy for redirects.
111+
if ( preg_match( '/^Location:/', $response_header ) ) {
112+
list($header, $value) = preg_split( '/: /', $response_header, 2 );
113+
$response_header = 'Location: ' . $_SERVER['REQUEST_URI'] . '?csurl=' . $value;
114+
}
115+
if ( !preg_match( '/^(Transfer-Encoding):/', $response_header ) ) {
111116
header( $response_header );
117+
}
118+
}
112119

113120
// finally, output the content
114121
print($response_content );

0 commit comments

Comments
 (0)