Esempio n. 1
0
 public function testAllowRedirect()
 {
     $conf = new HttpConfiguration(['allow_redirects' => false]);
     $this->assertFalse($conf->redirectsAllowed());
     $this->assertNull($conf->allowRedirectsMax());
     $conf->allowRedirectsMax(1);
     $this->assertTrue($conf->redirectsAllowed());
     $this->assertEquals(1, $conf->allowRedirectsMax());
     $this->assertTrue($conf->allowRedirectsReferer());
     $conf->allowRedirectsReferer(false);
     $this->assertFalse($conf->allowRedirectsReferer());
 }
Esempio n. 2
0
 /**
  * Specific method to prepare HTTP requests options
  * @param Configuration\HttpConfiguration $config
  */
 private function prepareHttp(Configuration\HttpConfiguration $config)
 {
     switch ($config->method) {
         case 'GET':
             $this->options[CURLOPT_HTTPGET] = true;
             break;
         case 'PUT':
             if (is_resource($config->body)) {
                 $this->options[CURLOPT_PUT] = true;
             } else {
                 $this->options[CURLOPT_CUSTOMREQUEST] = 'PUT';
             }
             break;
         default:
             $this->options[CURLOPT_CUSTOMREQUEST] = $config->method;
     }
     if ($config->redirectsAllowed()) {
         $this->options[CURLOPT_AUTOREFERER] = $config->allowRedirectsReferer();
         $this->options[CURLOPT_MAXREDIRS] = $config->allowRedirectsMax();
     } else {
         $this->options[CURLOPT_FOLLOWLOCATION] = false;
     }
     if (null !== $config->accept_encoding) {
         $this->options[CURLOPT_ENCODING] = $config->accept_encoding;
     }
     if (true === $config->verify) {
         $this->options[CURLOPT_SSL_VERIFYPEER] = true;
         $this->options[CURLOPT_SSL_VERIFYHOST] = 2;
         $this->options[CURLOPT_CAINFO] = CaBundle::getSystemCaRootBundlePath();
     } else {
         $this->options[CURLOPT_SSL_VERIFYPEER] = false;
         $this->options[CURLOPT_SSL_VERIFYHOST] = 0;
     }
 }