mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-10-24 22:25:09 +03:00
Merge 3a173a6dff into 3659552fac
This commit is contained in:
commit
a076730265
3 changed files with 27 additions and 2 deletions
|
|
@ -166,4 +166,29 @@ abstract class Request
|
|||
{
|
||||
return self::$scheme_ports[$scheme] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra headers as the flat list of "Name: value" lines both transports send.
|
||||
*
|
||||
* Callers pass either form: a list of ready lines, or an associative array
|
||||
* such as ['Accept-Encoding' => 'gzip']. The
|
||||
* associative form used to reach CURLOPT_HTTPHEADER as bare values, so the
|
||||
* header was sent as a malformed line and dropped.
|
||||
*
|
||||
* Some callers file a complete line under its own name
|
||||
* (['Authorization' => 'Authorization: Basic ...'] in the socket 401
|
||||
* retry). Such a value is kept as it is, otherwise it would go out
|
||||
* as "Authorization: Authorization: Basic ...".
|
||||
*/
|
||||
public static function headerLines(array $headers) : array
|
||||
{
|
||||
$lines = array();
|
||||
foreach ($headers as $name => $value) {
|
||||
$value = (string) $value;
|
||||
$lines[] = (\is_int($name) || 0 === \stripos($value, $name . ':'))
|
||||
? $value
|
||||
: "{$name}: {$value}";
|
||||
}
|
||||
return $lines;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class CURL extends \SnappyMail\HTTP\Request
|
|||
\curl_setopt($c, CURLOPT_CAINFO, $this->ca_bundle);
|
||||
}
|
||||
if ($extra_headers) {
|
||||
\curl_setopt($c, CURLOPT_HTTPHEADER, $extra_headers);
|
||||
\curl_setopt($c, CURLOPT_HTTPHEADER, static::headerLines($extra_headers));
|
||||
}
|
||||
if ($this->auth['user'] && $this->auth['type']) {
|
||||
if ($this->auth['type'] & self::AUTH_BEARER ) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Socket extends \SnappyMail\HTTP\Request
|
|||
$extra_headers['Authorization'] = static::$Authorization[$host];
|
||||
}
|
||||
if ($extra_headers) {
|
||||
$headers = \array_merge($headers, $extra_headers);
|
||||
$headers = \array_merge($headers, static::headerLines($extra_headers));
|
||||
}
|
||||
$headers = \implode("\r\n", $headers);
|
||||
if (!\is_null($body)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue