Example #1
0
 /**
  * Writes the $record with the writer $writerType or depending on the get
  * parameter format or of the mime type of the Accept header
  *
  * @param \PSX\Data\RecordInterface $record
  * @param string $writerType
  * @return void
  */
 private function setResponse(RecordInterface $record, $writerType = null)
 {
     // find best writer type
     $writer = $this->getResponseWriter($writerType);
     // set writer specific settings
     $this->configureWriter($writer);
     // write the response
     $response = $writer->write($record);
     // the response may have multiple presentations based on the Accept
     // header field
     if (!$this->response->hasHeader('Vary')) {
         $this->response->setHeader('Vary', 'Accept');
     }
     // set content type header if not available
     if (!$this->response->hasHeader('Content-Type')) {
         $contentType = $writer->getContentType();
         if ($contentType !== null) {
             $this->response->setHeader('Content-Type', $contentType);
         }
     }
     // for iframe file uploads we need an text/html content type header even
     // if we want serve json content. If all browsers support the FormData
     // api we can send file uploads per ajax but for now we use this hack.
     // Note do not rely on this param it will be removed as soon as possible
     if (isset($_GET['htmlMime'])) {
         $this->response->setHeader('Content-Type', 'text/html');
     }
     $this->response->getBody()->write($response);
 }
Example #2
0
File: Basic.php Project: seytar/psx
 public function send(ResponseInterface $response)
 {
     // remove body on specific status codes
     if (in_array($response->getStatusCode(), array(100, 101, 204, 304))) {
         $response->setBody(new StringStream(''));
     } elseif ($response->hasHeader('Location')) {
         $response->setBody(new StringStream(''));
     }
     if ($this->shouldSendHeader()) {
         // if we have an file stream body set custom header
         $this->prepareFileStream($response);
         // send status line
         $this->sendStatusLine($response);
         // send headers
         $this->sendHeaders($response);
     }
     // send body
     $this->sendBody($response);
 }
Example #3
0
 /**
  * Method which checks whether this is an valid response from an google
  * server
  */
 protected function assertGoogleResponse(ResponseInterface $response)
 {
     $this->assertTrue($response->getStatusCode() >= 200 && $response->getStatusCode() < 400);
     // google server always response with an Server header
     $this->assertTrue($response->hasHeader('Server'));
     // we assume that the response should be more the 128 bytes
     $this->assertTrue(strlen((string) $response->getBody()) > 128);
 }
Example #4
0
 /**
  * Returns an array containing all headers which gets saved in the cache
  *
  * @param \PSX\Http\ResponseInterface $response
  * @return array
  */
 protected function getCacheHeaders(ResponseInterface $response)
 {
     $headers = array('Last-Modified' => date(DateTime::HTTP));
     if ($response->hasHeader('Content-Type')) {
         $headers['Content-Type'] = $response->getHeader('Content-Type');
     }
     return $headers;
 }