From b6be18d585f8a36ed42ffa9d312798f04b06b887 Mon Sep 17 00:00:00 2001 From: triatic <42704418+triatic@users.noreply.github.com> Date: Mon, 29 Jul 2019 11:05:13 +0100 Subject: [PATCH] [contents] Respect passed headers for file_get_contents() (#1234) * [contents] Respect passed headers for file_get_contents() --- lib/contents.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/contents.php b/lib/contents.php index d59b0d01..8649c0b6 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -56,7 +56,20 @@ function getContents($url, $header = array(), $opts = array()){ // Use file_get_contents if in CLI mode with no root certificates defined if(php_sapi_name() === 'cli' && empty(ini_get('curl.cainfo'))) { - $data = @file_get_contents($url); + + $httpHeaders = ''; + + foreach ($header as $headerL) { + $httpHeaders .= $headerL . "\r\n"; + } + + $ctx = stream_context_create(array( + 'http' => array( + 'header' => $httpHeaders + ) + )); + + $data = @file_get_contents($url, 0, $ctx); if($data === false) { $errorCode = 500;