diff --git a/src/Response/StringResponse.php b/src/Response/StringResponse.php index f9ef99d8..3b0c41d1 100644 --- a/src/Response/StringResponse.php +++ b/src/Response/StringResponse.php @@ -60,6 +60,18 @@ public static function json($data, $status = 200, array $headers = []) return static::createResponse($json, $status, $headers, 'application/json'); } + /** + * Create an empty response with the given status code. + * + * @param int $status Status code for the response, if any. + * @param array $headers Headers for the response, if any. + * @return Response + */ + public static function blank($status = 200, array $headers = []) + { + return static::createResponse('', $status, $headers); + } + /** * This class is non-instantiable. */ @@ -71,7 +83,7 @@ private function __construct() * Create a Response from the provided information. * * Creates a Response using a php://temp stream, and writes the provided - * body to the stream; if non content-type header was provided, the given + * body to the stream; if no content-type header was provided, any given * $contentType is injected for it. * * @param string $body @@ -80,12 +92,12 @@ private function __construct() * @param string $contentType * @return Response */ - private static function createResponse($body, $status, array $headers, $contentType) + private static function createResponse($body, $status, array $headers, $contentType = null) { $response = new Response('php://temp', $status, $headers); $response->getBody()->write($body); - if ($response->hasHeader('content-type')) { + if ($contentType === null || $response->hasHeader('content-type')) { return $response; }