public function respond(Context $context) { $response = $context->getResponse(); if ($response->getBody()->getSize() === 0) { $context->withContentType('text/plain'); $context->write($response->getReasonPhrase()); } $headers = $response->getHeaders(); // remove default content-type // if (is_null($headers['Content-Type']) && isset($this['response.contentType'])) { // $headers['Content-Type'] = $this['response.contentType']; // } if (!headers_sent()) { header(sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase())); foreach ($response->getHeaders()->normalize() as $name => $value) { header(sprintf('%s: %s', $name, implode(', ', $value ?: [])), false); } } if (!isset(static::$STATUSES_EMPTY[$response->getStatusCode()])) { $body = $response->getBody(); if ($body->isSeekable()) { $body->rewind(); } while (!$body->eof()) { echo $body->read($this['response.chunkSize']); if (connection_status() != CONNECTION_NORMAL) { break; } } } // see koa for the rest }