From 8cfe509742524c9c9ad9db2d1c3c60248a738ef8 Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 26 Sep 2019 17:55:06 +0800 Subject: [PATCH] Correct Content-MD5 header format --- src/getallheaders.php | 12 ++++++++++-- tests/GetAllHeadersTest.php | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/getallheaders.php b/src/getallheaders.php index c7285a5..d0c46db 100644 --- a/src/getallheaders.php +++ b/src/getallheaders.php @@ -14,14 +14,22 @@ function getallheaders() $copy_server = array( 'CONTENT_TYPE' => 'Content-Type', 'CONTENT_LENGTH' => 'Content-Length', - 'CONTENT_MD5' => 'Content-Md5', + 'CONTENT_MD5' => 'Content-MD5', ); foreach ($_SERVER as $key => $value) { if (substr($key, 0, 5) === 'HTTP_') { $key = substr($key, 5); if (!isset($copy_server[$key]) || !isset($_SERVER[$key])) { - $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', $key)))); + $keys = explode('_', $key); + if (count($keys) === 2 && strtolower($keys[1]) === 'md5') { + $keys[0] = ucwords(strtolower($keys[0])); + $keys[1] = strtoupper($keys[1]); + $key = implode(' ', $keys); + } else { + $key = ucwords(strtolower(str_replace('_', ' ', $key))); + } + $key = str_replace(' ', '-', $key); $headers[$key] = $value; } } elseif (isset($copy_server[$key])) { diff --git a/tests/GetAllHeadersTest.php b/tests/GetAllHeadersTest.php index fb59597..d73d0aa 100644 --- a/tests/GetAllHeadersTest.php +++ b/tests/GetAllHeadersTest.php @@ -70,7 +70,7 @@ public function dataWorks() [ 'Content-MD5', [ - 'Content-Md5' => 'aef123', + 'Content-MD5' => 'aef123', ], [ 'CONTENT_MD5' => 'aef123', @@ -80,7 +80,7 @@ public function dataWorks() [ 'Content-MD5 (HTTP_CONTENT_MD5 only)', [ - 'Content-Md5' => 'f123', + 'Content-MD5' => 'f123', ], [ 'HTTP_CONTENT_MD5' => 'f123',