Skip to content

Commit 837fe20

Browse files
committed
Updated HTTP headers when a resource is created using URL
1 parent 6207d52 commit 837fe20

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/Resource/ResourceFactory.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
use function fopen;
2929
use function fwrite;
3030
use function get_debug_type;
31+
use function implode;
3132
use function is_file;
3233
use function is_string;
34+
use function parse_url;
3335
use function sprintf;
3436
use function stream_context_create;
3537
use function sys_get_temp_dir;
@@ -95,13 +97,28 @@ public function createResourceFromFile(PathInfoInterface $pathInfo, string $file
9597

9698
error_clear_last();
9799

100+
$headers = [
101+
"Accept-language: en\r\n",
102+
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\r\n",
103+
];
104+
105+
$parsedUrl = parse_url($filename) ?: [];
106+
107+
if (isset($parsedUrl['scheme'], $parsedUrl['host'])) {
108+
$headers[] = sprintf(
109+
"Referer: %s://%s\r\n",
110+
$parsedUrl['scheme'],
111+
$parsedUrl['host'],
112+
);
113+
}
114+
98115
$context = stream_context_create(
99116
options: [
100117
'http' => [
101118
'method' => 'GET',
102119
'protocol_version' => 1.1,
103120
'follow_location' => true,
104-
'header' => "Accept-language: en\r\n" . "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36\r\n",
121+
'header' => implode('', $headers),
105122
],
106123
],
107124
);

0 commit comments

Comments
 (0)