From b526e6b4159c64dd463b27626fa0b520ed20c309 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 11 Oct 2020 21:45:52 +0200 Subject: [PATCH] Fix GuzzleHttpClient - Add sink (= specify temp store for the body) - Fix HTTP header merge --- src/Network/HTTPRequest.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Network/HTTPRequest.php b/src/Network/HTTPRequest.php index 82eec8043..c37db4c9a 100644 --- a/src/Network/HTTPRequest.php +++ b/src/Network/HTTPRequest.php @@ -102,11 +102,17 @@ class HTTPRequest implements IHTTPRequest // $curlOptions[CURLOPT_MAXREDIRS] = 5; if (!empty($opts['accept_content'])) { - $curlOptions[CURLOPT_HTTPHEADER][] = ['Accept: ' . $opts['accept_content']]; + if (empty($curlOptions[CURLOPT_HTTPHEADER])) { + $curlOptions[CURLOPT_HTTPHEADER] = []; + } + array_push($curlOptions[CURLOPT_HTTPHEADER], 'Accept: ' . $opts['accept_content']); } if (!empty($opts['header'])) { - $curlOptions[CURLOPT_HTTPHEADER][] = $opts['header']; + if (empty($curlOptions[CURLOPT_HTTPHEADER])) { + $curlOptions[CURLOPT_HTTPHEADER] = []; + } + $curlOptions[CURLOPT_HTTPHEADER] = array_merge($opts['header'], $curlOptions[CURLOPT_HTTPHEADER]); } $curlOptions[CURLOPT_RETURNTRANSFER] = true; @@ -124,7 +130,10 @@ class HTTPRequest implements IHTTPRequest $curlOptions[CURLOPT_ENCODING] = ''; if (!empty($opts['headers'])) { - $curlOptions[CURLOPT_HTTPHEADER][] = $opts['headers']; + if (empty($curlOptions[CURLOPT_HTTPHEADER])) { + $curlOptions[CURLOPT_HTTPHEADER] = []; + } + $curlOptions[CURLOPT_HTTPHEADER] = array_merge($opts['headers'], $curlOptions[CURLOPT_HTTPHEADER]); } if (!empty($opts['nobody'])) { @@ -191,11 +200,12 @@ class HTTPRequest implements IHTTPRequest 'allow_redirect' => [ 'max' => 8, 'on_redirect' => $onRedirect, - 'on_headers' => $onHeaders, 'track_redirect' => true, 'strict' => true, 'referer' => true, ], + 'on_headers' => $onHeaders, + 'sink' => tempnam(get_temppath(), 'guzzle'), 'curl' => $curlOptions ]);