/** @test */ public function closedResponseShouldNotBeResumedOrPaused() { $response = new Response($this->stream, 'http', '1.0', '200', 'ok', array('content-type' => 'text/plain')); $this->stream->expects($this->never())->method('pause'); $this->stream->expects($this->never())->method('resume'); $response->handleEnd(); $response->resume(); $response->pause(); }
/** @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()); }
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); }
/** * @test */ public function http_with_includeResponse_with_buffer() { $testData1 = str_repeat("1", 1000); $testData2 = str_repeat("1", 1000); $testData3 = str_repeat("1", 1000); $complete = false; $error = false; $method = "GET"; $url = "https://www.example.com"; $requestData = new RequestData($method, $url); $request = new Request($this->connector, $requestData); $response = new Response($this->stream, 'HTTP', '1.0', '200', 'OK', ['Content-Type' => 'text/plain']); $source = $this->createHttpObservable($request, $method, $url)->includeResponse(); $source->subscribe(new CallbackObserver(function ($value) use(&$result) { $result = $value; }, function ($e) use(&$error) { $error = true; }, function () use(&$complete) { $complete = true; })); $request->emit("response", [$response]); $response->emit("data", [$testData1, $response]); $response->emit("data", [$testData2, $response]); $response->emit("data", [$testData3, $response]); $response->emit("end"); $this->assertEquals($result[0], $testData1 . $testData2 . $testData3); $this->assertInstanceOf('React\\HttpClient\\Response', $result[1]); $this->assertInstanceOf('React\\HttpClient\\Request', $result[2]); $this->assertTrue($complete); $this->assertFalse($error); }
/** * * @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; }
/** * 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()); }