Speedup CardDAV sync by remembering Authorization

This commit is contained in:
djmaze 2021-04-16 20:36:38 +02:00
parent f36ef03c1e
commit f6eb03d7ef
2 changed files with 13 additions and 4 deletions

View file

@ -11,14 +11,16 @@ class Socket extends \SnappyMail\HTTP\Request
return \function_exists('openssl_open');
}
private static $Authorization = [];
protected function __doRequest(string &$method, string &$request_url, &$body, array $extra_headers) : Response
{
$parts = \parse_url($request_url);
$host = $parts['host'];
// Set a default port.
$port = 0;
if (\array_key_exists('port', $parts)) {
$port = $parts['port'];
$host .= ":{$parts['port']}";
} else if ('http' === $parts['scheme'] || 'https' === $parts['scheme']) {
$parts['port'] = self::getSchemePort($parts['scheme']);
} else {
@ -31,11 +33,15 @@ class Socket extends \SnappyMail\HTTP\Request
$headers = array(
"{$method} {$parts['path']}".(isset($parts['query']) ? "?{$parts['query']}" : '')." HTTP/1.1",
"Host: ".$parts['host'].($port ? ":".$port : ''),
"Host: {$host}",
"User-Agent: {$this->user_agent}",
'Connection: Close',
);
if (isset($extra_headers['Authorization'])) {
static::$Authorization[$host] = $extra_headers['Authorization'];
} else if (isset(static::$Authorization[$host])) {
$extra_headers['Authorization'] = static::$Authorization[$host];
}
if ($extra_headers) {
$headers = \array_merge($headers, $extra_headers);
}

View file

@ -52,6 +52,9 @@ class Response
return \property_exists($this, $k) ? $this->$k : null;
}
/**
* returns string, array or null
*/
public function getHeader($names)
{
$names = \is_array($names) ? $names : array($names);