From 5d1ce3b1469b08d9849412e6a90456fae4616e1b Mon Sep 17 00:00:00 2001 From: mac Date: Tue, 7 Jul 2026 13:26:10 +0300 Subject: [PATCH] Add download docs --- engine/classes/DealProxy.php | 43 ++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/engine/classes/DealProxy.php b/engine/classes/DealProxy.php index 98c18d7..c89aea6 100644 --- a/engine/classes/DealProxy.php +++ b/engine/classes/DealProxy.php @@ -97,31 +97,46 @@ class DealProxy CURLOPT_CUSTOMREQUEST => $method, CURLOPT_POSTFIELDS => $body, CURLOPT_HTTPHEADER => $headers, - CURLOPT_HEADER => false, + CURLOPT_HEADER => true, )); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_VERBOSE, true); - $verbose = fopen('php://temp', 'w+'); - curl_setopt($ch, CURLOPT_STDERR, $verbose); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $curlError = curl_error($ch); - if ($curlError) { - rewind($verbose); - $verboseLog = stream_get_contents($verbose); - $this->logMessage('cURL VERBOSE: ' . $verboseLog); - $this->logMessage('cURL Error: ' . $curlError); - } else { - $this->logMessage('cURL Response (first 200 chars): ' . substr($response, 0, 200)); - $this->logMessage('HTTP Code: ' . $httpCode); - } curl_close($ch); + if ($curlError) { + $this->logMessage('cURL Error: ' . $curlError); + http_response_code(500); + echo $curlError; + return; + } + + $responseHeaders = substr($response, 0, $headerSize); + $responseBody = substr($response, $headerSize); + + preg_match_all('/^([^:]+):\s*(.+)$/m', $responseHeaders, $matches); + if (isset($matches[1])) { + for ($i = 0; $i < count($matches[1]); $i++) { + $hName = trim($matches[1][$i]); + $hValue = trim($matches[2][$i]); + if (strcasecmp($hName, 'Content-Type') === 0 || + strcasecmp($hName, 'Content-Disposition') === 0 || + strcasecmp($hName, 'Content-Length') === 0 || + strcasecmp($hName, 'Content-Transfer-Encoding') === 0 || + strcasecmp($hName, 'Cache-Control') === 0 || + strcasecmp($hName, 'Pragma') === 0) { + header("$hName: $hValue"); + } + } + } + http_response_code($httpCode); - echo $response; + echo $responseBody; } private function buildMultipartBody()