Exemple #1
0
 /**
  * Serialize HTTP headers to be sent in an FCGI record.
  * 
  * @param HttpResponse $response
  * @param int $size
  * @return string
  */
 protected function serializeHeaders(HttpResponse $response, int $size = null) : string
 {
     $reason = \trim($response->getReasonPhrase());
     if ('' === $reason) {
         $reason = Http::getReason($response->getStatusCode());
     }
     $buffer = \sprintf("Status: %03u%s\r\n", $response->getStatusCode(), \rtrim(' ' . $reason));
     if ($size !== null) {
         $buffer .= "Content-Length: {$size}\r\n";
     }
     foreach ($response->getHeaders() as $name => $header) {
         $name = Http::normalizeHeaderName($name);
         foreach ($header as $value) {
             $buffer .= $name . ': ' . $value . "\r\n";
         }
     }
     return $buffer;
 }