/**
  * @test
  */
 public function willReturnNullWhenMatchWasNotFound()
 {
     $this->request = $this->request->withHeader('Accept', 'text/html');
     $this->negotiator->expects($this->once())->method('getBest')->will($this->returnValue(null));
     $bestMatch = $this->manager->getBestMatch($this->request);
     $this->assertNull($bestMatch);
 }
 public function __invoke(ServerRequestInterface $request)
 {
     $forwardedFor = array();
     if ($this->trustPreviousReverseProxies && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $forwardedFor[] = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
     }
     $forwardedFor[] = $_SERVER['REMOTE_ADDR'];
     return $request->withHeader("X-Forwarded-For", implode(",", $forwardedFor));
 }
示例#3
0
文件: Request.php 项目: Mosaic/Mosaic
 /**
  * {@inheritdoc}
  */
 public function withHeader($name, $value)
 {
     return new static($this->wrapped->withHeader($name, $value));
 }
示例#4
0
 /**
  * {@inheritDoc}
  */
 public function withHeader($name, $value)
 {
     return new self($this->app, $this->psrRequest->withHeader($name, $value));
 }
示例#5
0
文件: Nik.php 项目: projek-xyz/id-nik
 /**
  * Assert request header and we only accept application/json or ajax request.
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request
  * @return \Psr\Http\Message\ServerRequestInterface
  * @throws \InvalidArgumentException If Request Accept header not application/json.
  */
 protected function assertRequestHeader(Request $request)
 {
     // If it's an AJAX request, return as is
     if ($request->getHeaderLine('X-Requested-With') == 'XMLHttpRequest') {
         return $request;
     }
     // Otherwise, split the Accept header
     $accepts = explode(',', $request->getHeaderLine('Accept'));
     // Make sure it's accept application/json
     if (in_array('application/json', $accepts)) {
         return $request->withHeader('X-Requested-With', 'XMLHttpRequest');
     }
     // Otherwise, throw it
     throw new InvalidArgumentException('Invalid request');
 }
 /**
  * Proxy to ServerRequestInterface::withHeader()
  *
  * {@inheritdoc}
  */
 public function withHeader($header, $value)
 {
     $new = $this->psrRequest->withHeader($header, $value);
     return new self($new, $this->originalRequest);
 }
示例#7
0
 /**
  * @inheritDoc
  */
 public function withHeader($name, $value)
 {
     $self = clone $this;
     $self->serverRequest = $this->serverRequest->withHeader($name, $value);
     return $self;
 }