コード例 #1
0
ファイル: ActionRequest.php プロジェクト: jivoo/http
 /**
  * Construct action request.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request Request to wrap.
  */
 public function __construct(\Psr\Http\Message\ServerRequestInterface $request)
 {
     parent::__construct($request->getBody());
     foreach ($request->getHeaders() as $name => $value) {
         $this->setHeader($name, $value);
     }
     $this->protocolVersion = $request->getProtocolVersion();
     $this->method = $request->getMethod();
     $this->requestTarget = $request->getRequestTarget();
     $this->uri = $request->getUri();
     $this->attributes = $request->getAttributes();
     $this->cookies = $request->getCookieParams();
     $this->data = $request->getParsedBody();
     $this->query = $request->getQueryParams();
     $this->server = $request->getServerParams();
     $this->files = $request->getUploadedFiles();
     if (isset($this->server['SCRIPT_NAME'])) {
         $this->attributes['basePath'] = dirname($this->server['SCRIPT_NAME']);
         $this->attributes['scriptName'] = basename($this->server['SCRIPT_NAME']);
     } else {
         $this->attributes['basePath'] = '/';
         $this->attributes['scriptName'] = 'index.php';
     }
     if (!isset($this->attributes['path'])) {
         $this->attributes['path'] = self::findPath($this);
     }
     if (!isset($this->attributes['rewrite'])) {
         $this->attributes['rewrite'] = false;
     }
     if (!isset($this->attributes['accepts'])) {
         $this->attributes['accepts'] = [];
         if (isset($this->server['HTTP_ACCEPT'])) {
             $contentTypes = explode(',', $this->server['HTTP_ACCEPT']);
             foreach ($contentTypes as $contentType) {
                 $contentType = explode(';', $contentType);
                 $this->attributes['accepts'][] = trim(strtolower($contentType[0]));
             }
         }
     }
     if (!isset($this->attributes['encodings'])) {
         $this->attributes['encodings'] = [];
         if (isset($this->server['HTTP_ACCEPT_ENCODING'])) {
             $acceptEncodings = explode(',', $this->server['HTTP_ACCEPT_ENCODING']);
             foreach ($acceptEncodings as $encoding) {
                 $this->attributes['encodings'][] = trim(strtolower($encoding));
             }
         }
     }
 }
コード例 #2
0
ファイル: Request.php プロジェクト: Mosaic/Mosaic
 /**
  * {@inheritdoc}
  */
 public function getProtocolVersion()
 {
     return $this->wrapped->getProtocolVersion();
 }
コード例 #3
0
ファイル: Request.php プロジェクト: tonis-io/tonis
 /**
  * {@inheritDoc}
  */
 public function getProtocolVersion()
 {
     return $this->psrRequest->getProtocolVersion();
 }
コード例 #4
0
ファイル: Response.php プロジェクト: nbish11/meek-http
 /**
  * https://github.com/symfony/http-foundation/blob/master/Response.php#L250
  * @param  PsrServerRequest $request [description]
  * @return self
  */
 public function prepare(PsrServerRequest $request)
 {
     $response = clone $this;
     if ($response->status->isInformational() || in_array($response->getStatusCode(), [204, 304])) {
         $response = $respone->withBody(new Stream('php://temp'))->withoutHeader('Content-Type')->withoutHeader('Content-Length');
     } else {
         // set content type based on request, if we haven't provided one
         if (!$response->hasHeader('Content-Type')) {
         }
         // fix content type
         $charset = $response->charset ?: 'UTF-8';
         if (!$response->hasHeader('Content-Type')) {
             $response = $response->withHeader('Content-Type', sprintf('text/html; charset=%s', $charset));
         } elseif (stripos($response->getHeaderLine('Content-Type'), 'text/') === 0 && stripos($response->getHeaderLine('Content-Type'), 'charset') === false) {
             $value = sprintf('%s; charset=%s', $response->getHeaderLine('Content-Type'), $charset);
             $response = $response->withHeader('Content-Type', $value);
         }
         // fix content length
         if ($response->hasHeader('Transfer-Encoding')) {
             $response = $response->withoutHeader('Content-Length');
         }
         if (!$response->hasHeader('Content-Length')) {
             $response->withHeader('Content-Length', (string) $this->getBody()->getSize());
         }
         // fix HEAD requests
         if ($request->getMethod() === 'HEAD') {
             // make sure content length is specified
             if (!$response->hasHeader('Content-Length')) {
                 $response = $response->withHeader('Content-Length', $response->getBody()->getSize());
             }
             // body should be empty
             $response = $respone->withBody(new Stream('php://temp'));
         }
     }
     // fix protocol
     if ($request->getProtocolVersion() !== '1.0') {
         $response = $response->withProtocolVersion('1.1');
     }
     // check if we need to send extra expire info headers
     if ($response->getProtocolVersion() === '1.0' && in_array('no-cache', $response->getHeader('Cache-Control'))) {
         $response = $response->withAddedHeader('Pragma', 'no-cache')->withAddedHeader('Expires', -1);
     }
     return $response;
 }