getHeaders() public method

public getHeaders ( )
Beispiel #1
0
 public function onLoad($body)
 {
     $this->done = true;
     $headers = $this->response->getHeaders();
     if (isset($headers['Location'])) {
         if ($this->deep > 0) {
             $this->pushQueue($headers['Location'], $this->deep - 1);
         }
         return;
     }
     $html = new Crawler();
     $html->addHtmlContent($body);
     $this->search->index($this->url, $html);
     if ($this->deep > 0) {
         $base = parse_url($this->url);
         $links = $html->filter('a');
         $links->each(function (Crawler $link) use($base) {
             $href = explode('#', $link->attr('href'))[0];
             $href = trim($href);
             if (empty($href)) {
                 return;
             }
             if ('/' === $href) {
                 return;
             }
             if (preg_match('/^https?:\\/\\//i', $href)) {
                 $url = $href;
             } else {
                 if (0 === strpos($href, '/')) {
                     $url = $base['scheme'] . '://' . $base['host'] . $href;
                 } else {
                     $url = $base['scheme'] . '://' . $base['host'] . (isset($base['path']) ? $base['path'] : '/') . $href;
                 }
             }
             if (HOMER_KEEP_HOST && $base['host'] !== parse_url($url, PHP_URL_HOST)) {
                 return;
             }
             $this->pushQueue($url, $this->deep - 1);
         });
     }
 }
 /**
  *
  */
 protected function handleResponse($request)
 {
     $this->progress->onResponse($this->httpResponse);
     $this->createStream($request);
     $response = new Response($this->httpResponse->getCode(), $this->httpResponse->getHeaders(), $this->stream, $this->httpResponse->getVersion(), $this->httpResponse->getReasonPhrase());
     if (!$this->options['stream']) {
         return $request->on('end', function () use($response) {
             $this->resolveResponse($response);
         });
     }
     $this->resolveResponse($response);
 }
Beispiel #3
0
 /** @test */
 public function chunkedEncodingResponse()
 {
     $stream = new ThroughStream();
     $response = new Response($stream, 'http', '1.0', '200', 'ok', ['content-type' => 'text/plain', 'transfer-encoding' => 'chunked']);
     $buffer = '';
     $response->on('data', function ($data, $stream) use(&$buffer) {
         $buffer .= $data;
     });
     $this->assertSame('', $buffer);
     $stream->write("4; abc=def\r\n");
     $this->assertSame('', $buffer);
     $stream->write("Wiki\r\n");
     $this->assertSame('Wiki', $buffer);
     $this->assertSame(['content-type' => 'text/plain'], $response->getHeaders());
 }
Beispiel #4
0
 /**
  * 
  * @param React\HttpClient\Response $clientResponse
  * 
  * @return self
  */
 public function mergeClientResponse($clientResponse)
 {
     $headers = new Collection(Arr::except($clientResponse->getHeaders(), $this->headersNotAllowed));
     $this->headers = $this->headers()->merge($headers->all());
     $this->clientResponse = $clientResponse;
     return $this;
 }
Beispiel #5
0
 /**
  * Transform a React Response to a valid PSR7 ResponseInterface instance.
  *
  * @param ReactResponse   $response
  * @param StreamInterface $body
  *
  * @return ResponseInterface
  */
 private function buildResponse(ReactResponse $response, StreamInterface $body)
 {
     $body->rewind();
     return $this->responseFactory->createResponse($response->getCode(), $response->getReasonPhrase(), $response->getHeaders(), $body, $response->getVersion());
 }