From 7bd010abedacf028ddf517bfcf77fad5301bd1a9 Mon Sep 17 00:00:00 2001 From: Torleif Berger Date: Mon, 6 Feb 2017 12:15:01 +0100 Subject: [PATCH] Make sure Transfer-Encoding is not set, regardless of case --- proxy.php | 23 +++++++++++++++-------- test/echo.php | 6 ++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/proxy.php b/proxy.php index c3f133d..6c2f359 100644 --- a/proxy.php +++ b/proxy.php @@ -1,5 +1,11 @@ 0); @@ -116,16 +121,18 @@ // Get content and headers $content = substr($out, $info['header_size']); -$header = substr($out, 0, $info['header_size']); +$headers = substr($out, 0, $info['header_size']); // Rename Set-Cookie header -$header = preg_replace('/^Set-Cookie:/im', 'X-Proxy-Set-Cookie:', $header); +$headers = preg_replace('/^Set-Cookie:/im', 'X-Proxy-Set-Cookie:', $headers); // Output headers -array_map('header', explode("\r\n", $header)); +foreach(explode("\r\n", $headers) as $h) + // HACK: Prevent chunked encoding issues (Issue #1) + if( ! preg_match('/^Transfer-Encoding:/i', $h)) + header($h, false); -// HACK: Prevent chunked encoding and gz issues (Issue #1) -header_remove('Transfer-Encoding'); +// HACK: Prevent gzip issue (Issue #1) header('Content-Length: '.strlen($content), true); // Output content diff --git a/test/echo.php b/test/echo.php index fe5ddfc..3564b0a 100644 --- a/test/echo.php +++ b/test/echo.php @@ -10,10 +10,12 @@ header_remove(); ini_set('zlib.output_compression', 'On'); -header('Content-Type: application/json; charset=utf-8'); + header('X-Test-Header: This header should come back through'); -setcookie('Test-Cookie', uniqid()); session_name('Test-Session'); session_start(); +setcookie('Test-Cookie-A', uniqid()); +setcookie('Test-Cookie-B', uniqid(), strtotime( '+1 days' )); +header('Content-Type: application/json; charset=utf-8'); echo json_encode(array_filter($info), JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_FORCE_OBJECT);