mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 19:07:01 +00:00
feat(refresh): send User-Agent header
This commit is contained in:
parent
22661baee0
commit
0da4f5c44e
1 changed files with 26 additions and 1 deletions
|
|
@ -10,6 +10,8 @@ if ($config['debug_mode']) {
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$agentVersion = trim(file_get_contents('./version.txt'));
|
||||||
|
|
||||||
class TwtxtFile {
|
class TwtxtFile {
|
||||||
public $mainURL = ''; // First found URL
|
public $mainURL = ''; // First found URL
|
||||||
public $URLs = [];
|
public $URLs = [];
|
||||||
|
|
@ -331,11 +333,34 @@ function updateCachedFile($filePath) {
|
||||||
|
|
||||||
# echo "lastModifiedHeader: $lastModifiedHeader<br>\n";
|
# echo "lastModifiedHeader: $lastModifiedHeader<br>\n";
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
global $agentVersion;
|
||||||
|
|
||||||
|
# TODO: Check this from the main page, not in this function
|
||||||
|
if (!array_key_exists('public_txt_url', $config) || !array_key_exists('public_nick', $config)) {
|
||||||
|
die("Check your config.ini file. 'public_txt_url' or 'public_nick' missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $config['public_txt_url'];
|
||||||
|
$nick = $config['public_nick'];
|
||||||
|
|
||||||
|
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
|
||||||
|
die("Check your config.ini file. 'public_txt_url' not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO: Add a validation for the nickname. For example at least 1 character.
|
||||||
|
|
||||||
|
$agentName = 'timeline';
|
||||||
|
$userAgentHeader = "User-Agent: $agentName/$agentVersion (+$url; @$nick)\r\n";
|
||||||
|
|
||||||
|
$header = $lastModifiedHeader ? "If-Modified-Since: $lastModifiedHeader\r\n" : '';
|
||||||
|
$header .= $userAgentHeader;
|
||||||
|
|
||||||
# Set up the HTTP context with the 'If-Modified-Since' header
|
# Set up the HTTP context with the 'If-Modified-Since' header
|
||||||
$options = [
|
$options = [
|
||||||
'http' => [
|
'http' => [
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'header' => $lastModifiedHeader ? "If-Modified-Since: $lastModifiedHeader\r\n" : '',
|
'header' => $header,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue