Example #1
0
 /**
  * @param \Blar\Curl\Curl $curl Curl.
  * @param \Blar\Http\HttpResponse $response Response.
  * @return $this
  */
 protected function configureCurl(Curl $curl, HttpResponse $response)
 {
     $curl->setMethod($this->getMethod());
     $curl->setUrl($this->getUrl());
     if ($this->getHeaders()) {
         $headers = $this->createHeadersArray($this->getHeaders());
         $curl->setOption(CURLOPT_HTTPHEADER, $headers);
     }
     if ($this->getBody()) {
         $curl->setBody($this->getBody());
     }
     $curl->setHeaderCallback(function ($header) use($response) {
         $response->setHeaderLine($header);
     });
     $curl->setWriteCallback(function ($part) use($response) {
         $response->addBodyPart($part);
     });
     return $this;
 }
Example #2
0
 public function testHeaderCallback()
 {
     $curl = new Curl();
     $curl->setUrl('http://httpbin.org/get?foo=23&bar=42');
     $curl->setHeaderCallback(function ($header) use(&$headers) {
         $headers[] = $header;
     });
     $curl->execute();
     $this->assertEquals(0, array_search('HTTP/1.1 200 OK', $headers));
     $this->assertGreaterThan(0, array_search('Content-Type: application/json', $headers));
 }