Пример #1
0
 /**
  * Configuration array
  *
  * @var array
  */
 protected function setUp()
 {
     if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY') && TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY) {
         list($host, $port) = explode(':', TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY, 2);
         if (!$host) {
             $this->markTestSkipped("No valid proxy host name or address specified.");
         }
         $port = (int) $port;
         if ($port == 0) {
             $port = 8080;
         } else {
             if ($port < 1 || $port > 65535) {
                 $this->markTestSkipped("{$port} is not a valid proxy port number. Should be between 1 and 65535.");
             }
         }
         $user = '';
         $pass = '';
         if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER') && TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER) {
             $user = TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER;
         }
         if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS') && TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS) {
             $pass = TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS;
         }
         $this->config = array('adapter' => 'Zend_Http_Client_Adapter_Proxy', 'proxy_host' => $host, 'proxy_port' => $port, 'proxy_user' => $user, 'proxy_pass' => $pass);
         parent::setUp();
     } else {
         $this->markTestSkipped("Zend_Http_Client proxy server tests are not enabled in TestConfiguration.php");
     }
 }
 /**
  * @group ZF-3189
  */
 public function testProxyAdapterDoesNotOverwriteExistingProxyAuthorizationHeader()
 {
     // Change the adapter
     $this->config['adapter'] = 'ZF3189_ProxyAdapter';
     parent::setUp();
     $base = preg_replace("/^http:/", "https:", $this->baseuri);
     $this->client->setUri($base . 'testSimpleRequests.php');
     $this->client->setHeaders('Proxy-Authorization', 'FooBarBaz');
     // Ensure we're proxying a HTTPS request
     $this->assertEquals('https', $this->client->getUri()->getScheme());
     // Perform the request
     $this->client->request();
     print_r($this->client->getAdapter()->getLastConnectHandshakeRequest());
     $resp = $this->client->getAdapter()->getLastConnectHandshakeRequest();
     $this->assertEquals(1, preg_match_all('/\\r\\nProxy-Authorization: ([^\\r\\n]+)\\r\\n/i', $resp, $matches));
     $this->assertEquals('FooBarBaz', $matches[1][0]);
 }