This commit is contained in:
2021-08-30 15:24:31 +08:00
parent 574ad26ced
commit 216363d8a7
2 changed files with 10 additions and 10 deletions
+1 -4
View File
@@ -177,10 +177,7 @@ trait Message
*/ */
private function addRequestHeader($key, $value) private function addRequestHeader($key, $value)
{ {
$this->headers[$key] = []; $this->headers[$key] = [$value];
foreach (explode(';', $value) as $item) {
$this->headers[$key][] = $item;
}
} }
+9 -6
View File
@@ -2,6 +2,8 @@
namespace Server\Message; namespace Server\Message;
use Exception;
use JetBrains\PhpStorm\Pure;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@@ -26,23 +28,24 @@ class Response implements ResponseInterface, \Server\ResponseInterface
/** /**
* *
*/ */
public function __construct() #[Pure] public function __construct()
{ {
$this->stream = new Stream(''); $this->stream = new Stream('');
} }
/** /**
* @param string $type * @param string $type
* @return $this * @return $this
*/ * @throws Exception
*/
public function withContentType(string $type): static public function withContentType(string $type): static
{ {
if (!in_array($type, [ if (!in_array($type, [
Response::CONTENT_TYPE_HTML, Response::CONTENT_TYPE_JSON, Response::CONTENT_TYPE_HTML, Response::CONTENT_TYPE_JSON,
Response::CONTENT_TYPE_STREAM, Response::CONTENT_TYPE_XML Response::CONTENT_TYPE_STREAM, Response::CONTENT_TYPE_XML
])) { ])) {
throw new \Exception('Wrong content type.'); throw new Exception('Wrong content type.');
} }
return $this->withHeader('Content-Type', $type); return $this->withHeader('Content-Type', $type);
} }