public function testPopulatesVersionStatusAndMessage() { $collector = new HeaderCollector(); $collector->collect(null, "HTTP/1.1 200 OK\r\n"); $collector->collect(null, "Content-type: text/html\r\n"); $collector->collect(null, "X-forwarded-for: 127.0.0.1\r\n"); $this->assertArrayHasKey("Content-type", $collector->retrieve()); $this->assertArrayHasKey("X-forwarded-for", $collector->retrieve()); $headers = $collector->retrieve(); $this->assertEquals("text/html", $headers["Content-type"]); $this->assertEquals("127.0.0.1", $headers["X-forwarded-for"]); $this->assertEquals("1.1", $collector->getVersion()); $this->assertEquals(200, $collector->getCode()); $this->assertEquals("OK", $collector->getMessage()); }
/** * Execute a Request object via cURL * * @param Request $request the request to execute * @param array $options additional curl options to set/override * * @return Response * * @throws CurlErrorException */ private function handleRaw(Request $request) { $curl = $this->lastCurlRequest = $this->getCurlRequest(); $curl->setOptionArray(array(CURLOPT_URL => $request->getUri(), CURLOPT_HTTPHEADER => $this->buildHeadersArray($request->headers), CURLINFO_HEADER_OUT => true)); $curl->setMethod($request->getMethod()); if ("POST" === $request->getMethod()) { $this->setPostFields($curl, $request); } if ("PUT" === $request->getMethod() && count($request->files->all()) > 0) { $file = current($request->files->all()); $curl->setOptionArray(array(CURLOPT_INFILE => '@' . $file->getRealPath(), CURLOPT_INFILESIZE => $file->getSize())); } $content = new ContentCollector(); $headers = new HeaderCollector(); // These options must not be tampered with to ensure proper functionality $curl->setOptionArray(array(CURLOPT_HEADERFUNCTION => array($headers, "collect"), CURLOPT_WRITEFUNCTION => array($content, "collect"))); $curl->execute(); $response = new Response($content->retrieve(), $headers->getCode(), $headers->retrieve()); $response->setProtocolVersion($headers->getVersion()); $response->setStatusCode($headers->getCode(), $headers->getMessage()); return $response; }