46 public function add($name, $value)
49 $name = (string)$name;
52 if ($name ==
'' || !static::validateName($name))
54 throw new \InvalidArgumentException(
"Invalid header name '{$name}'.");
57 if (!is_array($value))
62 foreach ($value as $key => $val)
64 $value[$key] = (string)$val;
65 if (!static::validateValue($value[$key]))
67 throw new \InvalidArgumentException(
"Invalid header value '{$value[$key]}'.");
71 $nameLower = strtolower($name);
73 if (!isset($this->headers[$nameLower]))
75 $this->headers[$nameLower] = [
80 foreach ($value as $val)
82 $this->headers[$nameLower][
'values'][] = $val;
295 $contentDisposition = $this->
get(
'Content-Disposition');
296 if ($contentDisposition !==
null)
301 $contentElements = explode(
';', $contentDisposition);
302 foreach ($contentElements as $contentElement)
304 $contentElement = trim($contentElement);
305 if (preg_match(
'/^filename\*=(.+)\'(.+)?\'(.+)$/', $contentElement, $matches))
307 $filename = $matches[3];
308 $encoding = $matches[1];
311 elseif (preg_match(
'/^filename="(.+)"$/', $contentElement, $matches))
313 $filename = $matches[1];
315 elseif (preg_match(
'/^filename=(.+)$/', $contentElement, $matches))
317 $filename = $matches[1];
323 $filename = urldecode($filename);
328 $filename = Encoding::convertEncoding($filename, $encoding, $charset);
396 foreach (explode(
"\n", $response) as $k => $header)
402 elseif (preg_match(
"/^[ \\t]/", $header))
404 if ($headerName !==
null)
408 $headers->add($headerName, trim($header));
410 catch (\InvalidArgumentException)
416 elseif (str_contains($header,
':'))
418 [$headerName, $headerValue] = explode(
':', $header, 2);
421 $headers->add($headerName, trim($headerValue));
423 catch (\InvalidArgumentException)