From c384a1e8451054247171ce9d85e0cc399d425edc Mon Sep 17 00:00:00 2001 From: Steffen Lange Date: Thu, 14 Jan 2021 22:30:40 +0100 Subject: [PATCH] Site-specific HTTP header fields, e.g. GitHub authentication --- HostOption.php | 12 ++++++++++++ PatchBase.php | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 HostOption.php diff --git a/HostOption.php b/HostOption.php new file mode 100644 index 0000000..8f910f6 --- /dev/null +++ b/HostOption.php @@ -0,0 +1,12 @@ + array('Authorization: token TOKEN') + ); + public static function get(string $key) { + return array_key_exists($key, self::$values) ? self::$values[$key] : false; + } +} + +?> diff --git a/PatchBase.php b/PatchBase.php index 384e313..c34056a 100644 --- a/PatchBase.php +++ b/PatchBase.php @@ -1,5 +1,7 @@ array('user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:1.0) Gecko/20200101 Patchbot/1.0')); + if (HostOption::get($host)) + $opt['http'] += array('header' => HostOption::get($host)); $ctx = stream_context_create($opt); - if ($str = file_get_contents($url, false, $ctx)) { + if ($str = @file_get_contents($url, false, $ctx)) { $this->data = $str; if ($json) { if (!($this->data = json_decode($str, true)))