getHeaders() public method

The header collection contains the currently registered HTTP headers.
public getHeaders ( ) : HeaderCollection
return HeaderCollection the header collection
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', $this->contentType);
     if ($this->filename !== null) {
         $response->getHeaders()->set('Content-Disposition', "attachment; filename=\"{$this->filename}\"");
     }
     $response->content = Yii::$app->{$this->converter}->convert($response->data, $this->options);
 }
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if ($this->gzip) {
         $this->contentType = $this->gzipContentType;
     } elseif (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $dom = new DOMDocument($this->version, $charset);
     $dom->formatOutput = true;
     $urlsetElement = $dom->createElement($this->rootTag);
     //urlset
     $dom->appendChild($urlsetElement);
     foreach ($this->xmlns as $xmlnsAttributeName => $xmlnsAttributeValue) {
         $urlsetElement->setAttributeNS('http://www.w3.org/2000/xmlns/', $xmlnsAttributeName, $xmlnsAttributeValue);
     }
     $this->buildXml($urlsetElement, $response->data, $dom);
     $xmlData = $dom->saveXML();
     //output
     if ($this->gzip) {
         $response->content = gzencode($xmlData);
         $response->getHeaders()->set('Content-Disposition', "attachment; filename=\"{$this->gzipFilename}\"");
     } else {
         $response->content = $xmlData;
     }
 }
Ejemplo n.º 3
0
 /**
  * Formats the specified response.
  * @param \yii\web\Response $response the response to be formatted.
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', 'text');
     //$response->setDownloadHeaders('error.pdf', 'application/pdf');
     //$response->setStatusCode(200);
     if ($response->data === null) {
         return;
     }
     echo '<pre>';
     var_export($response->data);
     /*
     $renderer = new \mPDF(
         'pl-x', // mode
         'A4', // format
         0, // font-size
         '', // font
         12, // margin-left
         12, // margin-right
         5, // margin-top
         5, // margin-bottom
         2, // margin-header
         2, // margin-footer
         'P' // orientation
     );
     $renderer->useSubstitutions = true;
     $renderer->simpleTables = false;
     if ($response->data !== null) {
         @$renderer->WriteHTML(\yii\helpers\Html::encode(var_export($response->data, true)));
     }
     $response->content = $renderer->Output('print', 'S');
     */
 }
Ejemplo n.º 4
0
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $response->charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $response->content = $response->data;
 }
Ejemplo n.º 5
0
 public function getHeaders()
 {
     $data = parent::getHeaders();
     foreach ($this->newheaders as $k => $v) {
         $data->set($k, $v);
     }
     return $data;
 }
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $dom = new DOMDocument($this->version, $this->encoding === null ? $response->charset : $this->encoding);
     $root = new DOMElement($this->rootTag);
     $dom->appendChild($root);
     $this->buildXml($root, $response->data);
     $response->content = $dom->saveXML();
 }
Ejemplo n.º 7
0
 /**
  * Formats response data in JSONP format.
  * @param Response $response
  */
 protected function formatJsonp($response)
 {
     $response->getHeaders()->set('Content-Type', 'application/javascript; charset=UTF-8');
     if (is_array($response->data) && isset($response->data['data'], $response->data['callback'])) {
         $response->content = sprintf('%s(%s);', $response->data['callback'], Json::encode($response->data['data']));
     } else {
         $response->content = '';
         Yii::warning("The 'jsonp' response requires that the data be an array consisting of both 'data' and 'callback' elements.", __METHOD__);
     }
 }
 /**
  * Formats response data in JSON format.
  * @param Response $response
  */
 protected function formatJson($response)
 {
     $response->getHeaders()->set('Content-Type', 'application/json; charset=UTF-8');
     if ($response->data !== null) {
         $options = $this->encodeOptions;
         if ($this->prettyPrint) {
             $options |= JSON_PRETTY_PRINT;
         }
         $response->content = Json::encode($response->data, $options);
     }
 }
 /**
  * @param string $seq
  * @param string $tag
  * @param boolean $passthru whether to send response to the browser or render it as plain text
  * @return Response
  * @throws HttpException
  */
 public function run($seq, $tag, $passthru = false)
 {
     $this->controller->loadData($tag);
     $timings = $this->panel->calculateTimings();
     if (!isset($timings[$seq])) {
         throw new HttpException(404, 'Log message not found.');
     }
     $requestInfo = $timings[$seq]['info'];
     $httpRequest = $this->createRequestFromLog($requestInfo);
     $httpResponse = $httpRequest->send();
     $httpResponse->getHeaders()->get('content-type');
     $response = new Response(['format' => Response::FORMAT_RAW]);
     if ($passthru) {
         foreach ($httpResponse->getHeaders() as $name => $value) {
             $response->getHeaders()->set($name, $value);
         }
         $response->content = $httpResponse->content;
         return $response;
     }
     $response->getHeaders()->add('content-type', 'text/plain');
     $response->content = $httpResponse->toString();
     return $response;
 }
Ejemplo n.º 10
0
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     if ($response->data !== null) {
         $dom = new DOMDocument($this->version, $charset);
         $root = new DOMElement($this->rootTag);
         $dom->appendChild($root);
         $this->buildXml($root, $response->data);
         $response->content = $dom->saveXML();
     }
 }
 /**
  * Formats response data in JSON format.
  * @link http://jsonapi.org/format/upcoming/#document-structure
  * @param Response $response
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', 'application/vnd.api+json; charset=UTF-8');
     if ($response->data !== null) {
         $options = $this->encodeOptions;
         if ($this->prettyPrint) {
             $options |= JSON_PRETTY_PRINT;
         }
         if ($response->isClientError || $response->isServerError) {
             if (ArrayHelper::isAssociative($response->data)) {
                 $response->data = [$response->data];
             }
             $apiDocument = ['errors' => $response->data];
         } elseif (ArrayHelper::keyExists('data', $response->data)) {
             $apiDocument = $response->data;
         } else {
             $apiDocument = ['meta' => $response->data];
         }
         $response->content = Json::encode($apiDocument, $options);
     }
 }
Ejemplo n.º 12
0
 /**
  * Restores response properties from the given data
  * @param Response $response the response to be restored
  * @param array $data the response property data
  * @since 2.0.3
  */
 protected function restoreResponse($response, $data)
 {
     if (isset($data['format'])) {
         $response->format = $data['format'];
     }
     if (isset($data['version'])) {
         $response->version = $data['version'];
     }
     if (isset($data['statusCode'])) {
         $response->statusCode = $data['statusCode'];
     }
     if (isset($data['statusText'])) {
         $response->statusText = $data['statusText'];
     }
     if (isset($data['headers']) && is_array($data['headers'])) {
         $headers = $response->getHeaders()->toArray();
         $response->getHeaders()->fromArray(array_merge($data['headers'], $headers));
     }
     if (isset($data['cookies']) && is_array($data['cookies'])) {
         $cookies = $response->getCookies()->toArray();
         $response->getCookies()->fromArray(array_merge($data['cookies'], $cookies));
     }
 }
Ejemplo n.º 13
0
 /**
  * Adds the CORS headers to the response
  * @param Response $response
  * @param array CORS headers which have been computed
  */
 public function addCorsHeaders($response, $headers)
 {
     if (empty($headers) === false) {
         $responseHeaders = $response->getHeaders();
         foreach ($headers as $field => $value) {
             $responseHeaders->set($field, $value);
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * Adds the rate limit headers to the response
  * @param Response $response
  * @param int $limit the maximum number of allowed requests during a period
  * @param int $remaining the remaining number of allowed requests within the current period
  * @param int $reset the number of seconds to wait before having maximum number of allowed requests again
  */
 public function addRateLimitHeaders($response, $limit, $remaining, $reset)
 {
     if ($this->enableRateLimitHeaders) {
         $response->getHeaders()->set('X-Rate-Limit-Limit', $limit)->set('X-Rate-Limit-Remaining', $remaining)->set('X-Rate-Limit-Reset', $reset);
     }
 }
Ejemplo n.º 15
0
 /**
  * Formats the specified response.
  *
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', 'application/pdf');
     $response->content = $this->formatPdf($response);
 }