
SwooleHttpResponse::write 메서드는 HTTP 응답 헤더를 전부 보낸 후에만 호출할 수 있습니다.
HTTP 헤더를 별도로 전달하고 싶다면, SwooleHttpResponse::write 메서드를 사용하기 전에 HTTP 헤더를 모두 작성한 후에 호출할 수 있습니다.
예를 들어, 다음 코드를 사용할 수 있습니다.
#hostingforum.kr
php
$response = new SwooleHttpResponse();
$response->write("HTTP/1.1 200 OKrn");
$response->write("Content-Type: text/htmlrn");
$response->write("rn");
// HTTP 헤더를 별도로 전달할 수 있습니다.
$response->write("X-Custom-Header: custom-valuern");
$response->write("...");
또는, HTTP 헤더를 별도로 전달할 수 있도록 SwooleHttpResponse 클래스를 상속하여 사용할 수 있습니다.
#hostingforum.kr
php
class CustomResponse extends SwooleHttpResponse
{
public function write($data)
{
if (strpos($data, "rnrn") !== false) {
// HTTP 헤더가 끝났습니다.
parent::write($data);
} else {
// HTTP 헤더가 아직 끝나지 않았습니다.
$this->body .= $data;
}
}
}
이러한 방법으로 HTTP 헤더를 별도로 전달할 수 있습니다.
2025-05-20 07:12