From 4285727fc2f2add1be1b46a3580e12314b1f9eb7 Mon Sep 17 00:00:00 2001 From: noname <37553600+yhvhdio@users.noreply.github.com> Date: Sun, 7 Aug 2022 16:25:05 -0400 Subject: [PATCH] fix json post requests --- Proxy.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Proxy.php b/Proxy.php index 5691aea..b2ae725 100644 --- a/Proxy.php +++ b/Proxy.php @@ -265,12 +265,26 @@ protected static function isAuthenticated() return !static::$ENABLE_AUTH || static::ri($_SERVER[static::$HEADER_HTTP_PROXY_AUTH]) === static::$AUTH_KEY; } + /** + * @return string + */ + protected static function getContentType() + { + // LiteSpeed server only sends 'CONTENT_TYPE'. + // The CGI RFC specifies that the Content-Type header value should be stored in CONTENT_TYPE, + // so since 7 version PHP "Fixed bug #66606 (Sets HTTP_CONTENT_TYPE but not CONTENT_TYPE)." https://www.php.net/ChangeLog-7.php. + // https://stackoverflow.com/a/5519834. + return self::ri( $_SERVER['CONTENT_TYPE'], self::ri( $_SERVER['HTTP_CONTENT_TYPE'], '' ) ); + } + /** * @param string[] $skippedHeaders * @return string[] */ protected static function getIncomingRequestHeaders($skippedHeaders = []) { + $_SERVER['HTTP_CONTENT_TYPE'] = self::getContentType();; + $results = []; foreach ($_SERVER as $key => $value) { if (in_array($key, $skippedHeaders)) { @@ -324,7 +338,11 @@ protected static function createRequest($targetURL) } } - curl_setopt($request, CURLOPT_POSTFIELDS, $data + $_POST); + if ( 'application/json' !== strtolower( self::getContentType() ) ) { + curl_setopt($request, CURLOPT_POSTFIELDS, $data + $_POST); + } else { + curl_setopt($request, CURLOPT_POSTFIELDS, file_get_contents('php://input')); + } } $headers = static::getIncomingRequestHeaders(static::getSkippedHeaders());