コード例 #1
0
ファイル: HttpRequest.php プロジェクト: koolkode/async-http
 public function __debugInfo() : array
 {
     $headers = [];
     foreach ($this->getHeaders() as $k => $header) {
         foreach ($header as $v) {
             $headers[] = \sprintf('%s: %s', Http::normalizeHeaderName($k), $v);
         }
     }
     \sort($headers, SORT_NATURAL);
     return ['protocol' => \sprintf('HTTP/%s', $this->protocolVersion), 'method' => $this->method, 'uri' => (string) $this->uri, 'target' => $this->getRequestTarget(), 'headers' => $headers, 'addresses' => $this->addresses, 'body' => $this->body, 'attributes' => \array_keys($this->attributes)];
 }
コード例 #2
0
ファイル: Connector.php プロジェクト: koolkode/async-http
 protected function serializeHeaders(HttpRequest $request, int $size = null)
 {
     if (\in_array('upgrade', $request->getHeaderTokenValues('Connection'))) {
         $request = $request->withHeader('Connection', 'upgrade');
     } else {
         $request = $request->withHeader('Connection', $this->keepAlive ? 'keep-alive' : 'close');
     }
     $buffer = \sprintf("%s %s HTTP/%s\r\n", $request->getMethod(), $request->getRequestTarget(), $request->getProtocolVersion());
     if ($this->keepAlive) {
         $buffer .= \sprintf("Keep-Alive: timeout=%u\r\n", $this->pool->getMaxLifetime());
     }
     if ($size === null) {
         $buffer .= "Transfer-Encoding: chunked\r\n";
     } else {
         $buffer .= "Content-Length: {$size}\r\n";
     }
     foreach ($request->getHeaders() as $name => $header) {
         $name = Http::normalizeHeaderName($name);
         foreach ($header as $value) {
             $buffer .= $name . ': ' . $value . "\r\n";
         }
     }
     return $buffer;
 }
コード例 #3
0
ファイル: Handler.php プロジェクト: koolkode/async-http
 /**
  * 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;
 }
コード例 #4
0
ファイル: Driver.php プロジェクト: koolkode/async-http
 /**
  * Serialize HTTP response headers into a string.
  */
 protected function serializeHeaders(HttpResponse $response, bool &$close, int $size = null, bool $nobody = false, bool $deferred = false) : string
 {
     $reason = \trim($response->getReasonPhrase());
     if ($reason === '') {
         $reason = \trim(Http::getReason($response->getStatusCode()));
     }
     if (!$response->hasHeader('Connection')) {
         $response = $response->withHeader('Connection', $close ? 'close' : 'keep-alive');
     }
     if (!$close) {
         $response = $response->withHeader('Keep-Alive', '30');
     }
     $buffer = \sprintf("HTTP/%s %u%s\r\n", $response->getProtocolVersion(), $response->getStatusCode(), \rtrim(' ' . $reason));
     if (!$nobody) {
         if ($deferred) {
             $close = true;
         } else {
             if ((double) $response->getProtocolVersion() > 1) {
                 if ($size === null) {
                     $buffer .= "Transfer-Encoding: chunked\r\n";
                 } else {
                     $buffer .= "Content-Length: {$size}\r\n";
                 }
             } elseif ($size !== null) {
                 $buffer .= "Content-Length: {$size}\r\n";
             } else {
                 $close = true;
             }
         }
     }
     foreach ($response->getHeaders() as $name => $header) {
         $name = Http::normalizeHeaderName($name);
         foreach ($header as $value) {
             $buffer .= $name . ': ' . $value . "\r\n";
         }
     }
     return $buffer;
 }