当前位置: 首页>>代码示例>>PHP>>正文


PHP drupal_generate_test_ua函数代码示例

本文整理汇总了PHP中drupal_generate_test_ua函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_generate_test_ua函数的具体用法?PHP drupal_generate_test_ua怎么用?PHP drupal_generate_test_ua使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了drupal_generate_test_ua函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testUserAgentValidation

 /**
  * Test validation of the User-Agent header we use to perform test requests.
  */
 public function testUserAgentValidation()
 {
     global $base_url;
     // Logout the user which was logged in during test-setup.
     $this->drupalLogout();
     $system_path = $base_url . '/' . drupal_get_path('module', 'system');
     $HTTP_path = $system_path . '/tests/http.php/user/login';
     $https_path = $system_path . '/tests/https.php/user/login';
     // Generate a valid simpletest User-Agent to pass validation.
     $this->assertTrue(preg_match('/simpletest\\d+/', $this->databasePrefix, $matches), 'Database prefix contains simpletest prefix.');
     $test_ua = drupal_generate_test_ua($matches[0]);
     $this->additionalCurlOptions = array(CURLOPT_USERAGENT => $test_ua);
     // Test pages only available for testing.
     $this->drupalGet($HTTP_path);
     $this->assertResponse(200, 'Requesting http.php with a legitimate simpletest User-Agent returns OK.');
     $this->drupalGet($https_path);
     $this->assertResponse(200, 'Requesting https.php with a legitimate simpletest User-Agent returns OK.');
     // Now slightly modify the HMAC on the header, which should not validate.
     $this->additionalCurlOptions = array(CURLOPT_USERAGENT => $test_ua . 'X');
     $this->drupalGet($HTTP_path);
     $this->assertResponse(403, 'Requesting http.php with a bad simpletest User-Agent fails.');
     $this->drupalGet($https_path);
     $this->assertResponse(403, 'Requesting https.php with a bad simpletest User-Agent fails.');
     // Use a real User-Agent and verify that the special files http.php and
     // https.php can't be accessed.
     $this->additionalCurlOptions = array(CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
     $this->drupalGet($HTTP_path);
     $this->assertResponse(403, 'Requesting http.php with a normal User-Agent fails.');
     $this->drupalGet($https_path);
     $this->assertResponse(403, 'Requesting https.php with a normal User-Agent fails.');
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:34,代码来源:SimpleTestBrowserTest.php

示例2: onBeforeSendRequest

 /**
  * Event callback for the 'before' event
  */
 public function onBeforeSendRequest(BeforeEvent $event)
 {
     // If the database prefix is being used by SimpleTest to run the tests in a copied
     // database then set the user-agent header to the database prefix so that any
     // calls to other Drupal pages will run the SimpleTest prefixed database. The
     // user-agent is used to ensure that multiple testing sessions running at the
     // same time won't interfere with each other as they would if the database
     // prefix were stored statically in a file or database variable.
     if ($test_prefix = drupal_valid_test_ua()) {
         $event->getRequest()->setHeader('User-Agent', drupal_generate_test_ua($test_prefix));
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:15,代码来源:HttpRequestSubscriber.php

示例3: __invoke

 /**
  * {@inheritdoc}
  *
  * HTTP middleware that replaces the user agent for simpletest requests.
  */
 public function __invoke()
 {
     // If the database prefix is being used by SimpleTest to run the tests in a copied
     // database then set the user-agent header to the database prefix so that any
     // calls to other Drupal pages will run the SimpleTest prefixed database. The
     // user-agent is used to ensure that multiple testing sessions running at the
     // same time won't interfere with each other as they would if the database
     // prefix were stored statically in a file or database variable.
     return function ($handler) {
         return function (RequestInterface $request, array $options) use($handler) {
             if ($test_prefix = drupal_valid_test_ua()) {
                 $request = $request->withHeader('User-Agent', drupal_generate_test_ua($test_prefix));
             }
             return $handler($request, $options);
         };
     };
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:22,代码来源:TestHttpClientMiddleware.php

示例4: __invoke

 /**
  * {@inheritdoc}
  *
  * HTTP middleware that replaces the user agent for simpletest requests.
  */
 public function __invoke()
 {
     // If the database prefix is being used by SimpleTest to run the tests in a copied
     // database then set the user-agent header to the database prefix so that any
     // calls to other Drupal pages will run the SimpleTest prefixed database. The
     // user-agent is used to ensure that multiple testing sessions running at the
     // same time won't interfere with each other as they would if the database
     // prefix were stored statically in a file or database variable.
     return function ($handler) {
         return function (RequestInterface $request, array $options) use($handler) {
             if ($test_prefix = drupal_valid_test_ua()) {
                 $request = $request->withHeader('User-Agent', drupal_generate_test_ua($test_prefix));
             }
             return $handler($request, $options)->then(function (ResponseInterface $response) use($request) {
                 if (!drupal_valid_test_ua()) {
                     return $response;
                 }
                 $headers = $response->getHeaders();
                 foreach ($headers as $header_name => $header_values) {
                     if (preg_match('/^X-Drupal-Assertion-[0-9]+$/', $header_name, $matches)) {
                         foreach ($header_values as $header_value) {
                             // Call \Drupal\simpletest\WebTestBase::error() with the parameters from
                             // the header.
                             $parameters = unserialize(urldecode($header_value));
                             if (count($parameters) === 3) {
                                 throw new \Exception($parameters[1] . ': ' . $parameters[0] . "\n" . Error::formatBacktrace([$parameters[2]]));
                             } else {
                                 throw new \Exception('Error thrown with the wrong amount of parameters.');
                             }
                         }
                     }
                 }
                 return $response;
             });
         };
     };
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:42,代码来源:TestHttpClientMiddleware.php

示例5: curlInitialize

 /**
  * Initializes the cURL connection.
  *
  * If the simpletest_httpauth_credentials variable is set, this function will
  * add HTTP authentication headers. This is necessary for testing sites that
  * are protected by login credentials from public access.
  * See the description of $curl_options for other options.
  */
 protected function curlInitialize()
 {
     global $base_url;
     if (!isset($this->curlHandle)) {
         $this->curlHandle = curl_init();
         // Some versions/configurations of cURL break on a NULL cookie jar, so
         // supply a real file.
         if (empty($this->cookieFile)) {
             $this->cookieFile = $this->publicFilesDirectory . '/cookie.jar';
         }
         $curl_options = array(CURLOPT_COOKIEJAR => $this->cookieFile, CURLOPT_URL => $base_url, CURLOPT_FOLLOWLOCATION => FALSE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE, CURLOPT_HEADERFUNCTION => array(&$this, 'curlHeaderCallback'), CURLOPT_USERAGENT => $this->databasePrefix, CURLOPT_SAFE_UPLOAD => TRUE);
         if (isset($this->httpAuthCredentials)) {
             $curl_options[CURLOPT_HTTPAUTH] = $this->httpAuthMethod;
             $curl_options[CURLOPT_USERPWD] = $this->httpAuthCredentials;
         }
         // curl_setopt_array() returns FALSE if any of the specified options
         // cannot be set, and stops processing any further options.
         $result = curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
         if (!$result) {
             throw new \UnexpectedValueException('One or more cURL options could not be set.');
         }
     }
     // We set the user agent header on each request so as to use the current
     // time and a new uniqid.
     if (preg_match('/simpletest\\d+/', $this->databasePrefix, $matches)) {
         curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0]));
     }
 }
开发者ID:Wylbur,项目名称:gj,代码行数:36,代码来源:WebTestBase.php

示例6: prepareRequest

 /**
  * Prepare for a request to testing site.
  *
  * The testing site is protected via a SIMPLETEST_USER_AGENT cookie that is
  * checked by drupal_valid_test_ua().
  *
  * @see drupal_valid_test_ua()
  */
 protected function prepareRequest()
 {
     $session = $this->getSession();
     $session->setCookie('SIMPLETEST_USER_AGENT', drupal_generate_test_ua($this->databasePrefix));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:BrowserTestBase.php

示例7: bangpound_drupal_http_request

/**
 * Overrides Drupal core HTTP request function with Guzzle.
 *
 * @see drupal_http_request()
 */
function bangpound_drupal_http_request($url, array $options = array())
{
    $result = new stdClass();
    // Parse the URL and make sure we can handle the schema.
    $uri = @parse_url($url);
    if ($uri == FALSE) {
        $result->error = 'unable to parse URL';
        $result->code = -1001;
        return $result;
    }
    if (!isset($uri['scheme'])) {
        $result->error = 'missing schema';
        $result->code = -1002;
        return $result;
    }
    timer_start(__FUNCTION__);
    // Merge the default options.
    $options += array('headers' => array(), 'method' => 'GET', 'data' => NULL, 'max_redirects' => 3, 'timeout' => 30.0, 'context' => NULL);
    // Merge the default headers.
    $options['headers'] += array('User-Agent' => 'Drupal (+http://drupal.org/)');
    // Concessions to Guzzle.
    if (isset($options['data'])) {
        $options['body'] = $options['data'];
    }
    if (!$options['max_redirects']) {
        $options['allow_redirects'] = FALSE;
    }
    // Use a proxy if one is defined and the host is not on the excluded list.
    $proxy_server = variable_get('proxy_server', '');
    if ($proxy_server && _drupal_http_use_proxy($uri['host'])) {
        // Set the scheme so we open a socket to the proxy server.
        $uri['scheme'] = 'proxy';
        // Set the path to be the full URL.
        $uri['path'] = $url;
        // Since the URL is passed as the path, we won't use the parsed query.
        unset($uri['query']);
        // Add in username and password to Proxy-Authorization header if needed.
        if ($proxy_username = variable_get('proxy_username', '')) {
            $proxy_password = variable_get('proxy_password', '');
            $options['headers']['Proxy-Authorization'] = 'Basic ' . base64_encode($proxy_username . (!empty($proxy_password) ? ":" . $proxy_password : ''));
        }
        // Some proxies reject requests with any User-Agent headers, while others
        // require a specific one.
        $proxy_user_agent = variable_get('proxy_user_agent', '');
        // The default value matches neither condition.
        if ($proxy_user_agent === NULL) {
            unset($options['headers']['User-Agent']);
        } elseif ($proxy_user_agent) {
            $options['headers']['User-Agent'] = $proxy_user_agent;
        }
    }
    // Make sure the socket opened properly.
    // @todo Migrate error checking.
    // If the server URL has a user then attempt to use basic authentication.
    // @todo Migrate authentication.
    // If the database prefix is being used by SimpleTest to run the tests in a copied
    // database then set the user-agent header to the database prefix so that any
    // calls to other Drupal pages will run the SimpleTest prefixed database. The
    // user-agent is used to ensure that multiple testing sessions running at the
    // same time won't interfere with each other as they would if the database
    // prefix were stored statically in a file or database variable.
    $test_info =& $GLOBALS['drupal_test_info'];
    if (!empty($test_info['test_run_id'])) {
        $options['headers']['User-Agent'] = drupal_generate_test_ua($test_info['test_run_id']);
    }
    // Calculate how much time is left of the original timeout value.
    $timeout = $options['timeout'] - timer_read(__FUNCTION__) / 1000;
    if ($timeout > 0) {
        /** @see \Guzzle\Http\StaticClient::request() */
        static $client;
        if (!$client) {
            $client = new \Guzzle\Http\Client();
        }
        $request = $client->createRequest($options['method'], $url, null, null, $options);
        if ($options['max_redirects']) {
            $client->getConfig()->set('redirect.max', $options['max_redirects']);
        }
        if (isset($options['stream'])) {
            if ($options['stream'] instanceof \Guzzle\Stream\StreamRequestFactoryInterface) {
                $response = $options['stream']->fromRequest($request);
            } elseif ($options['stream'] == true) {
                $streamFactory = new \Guzzle\Stream\PhpStreamRequestFactory();
                $response = $streamFactory->fromRequest($request);
            }
        } else {
            $response = $request->send();
        }
        $result->request = $request->__toString();
    } else {
        $result->code = HTTP_REQUEST_TIMEOUT;
        $result->error = 'request timed out';
        return $result;
    }
    if (isset($response)) {
        // Parse response headers from the response body.
//.........这里部分代码省略.........
开发者ID:bangpound,项目名称:drupal-bridge,代码行数:101,代码来源:override_functions.php

示例8: curlInitialize

 /**
  * Initializes the cURL connection.
  *
  * If the simpletest_httpauth_credentials variable is set, this function will
  * add HTTP authentication headers. This is necessary for testing sites that
  * are protected by login credentials from public access.
  * See the description of $curl_options for other options.
  */
 protected function curlInitialize()
 {
     global $base_url;
     if (!isset($this->curlHandle)) {
         $this->curlHandle = curl_init();
         $curl_options = array(CURLOPT_COOKIEJAR => $this->cookieFile, CURLOPT_URL => $base_url, CURLOPT_FOLLOWLOCATION => FALSE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE, CURLOPT_HEADERFUNCTION => array(&$this, 'curlHeaderCallback'), CURLOPT_USERAGENT => $this->databasePrefix);
         if (isset($this->httpauth_credentials)) {
             $curl_options[CURLOPT_HTTPAUTH] = $this->httpauth_method;
             $curl_options[CURLOPT_USERPWD] = $this->httpauth_credentials;
         }
         curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
         // By default, the child session name should be the same as the parent.
         $this->session_name = session_name();
     }
     // We set the user agent header on each request so as to use the current
     // time and a new uniqid.
     if (preg_match('/simpletest\\d+/', $this->databasePrefix, $matches)) {
         curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0]));
     }
 }
开发者ID:rlugojr,项目名称:livereload-examples,代码行数:28,代码来源:drupal_web_test_case.php

示例9: _bim_http_request


//.........这里部分代码省略.........
         $result->error = trim($errstr) ? trim($errstr) : t('Error opening socket @socket', array('@socket' => $socket));
         // Mark that this request failed. This will trigger a check of the web
         // server's ability to make outgoing HTTP requests the next time that
         // requirements checking is performed.
         // See system_requirements().
         //variable_set('_bim_http_request_fails', TRUE);
         return $result;
     }
     // Construct the path to act on.
     $path = isset($uri['path']) ? $uri['path'] : '/';
     if (isset($uri['query'])) {
         $path .= '?' . $uri['query'];
     }
     // Only add Content-Length if we actually have any content or if it is a POST
     // or PUT request. Some non-standard servers get confused by Content-Length in
     // at least HEAD/GET requests, and Squid always requires Content-Length in
     // POST/PUT requests.
     $content_length = strlen($options['data']);
     if ($content_length > 0 || $options['method'] == 'POST' || $options['method'] == 'PUT') {
         $options['headers']['Content-Length'] = $content_length;
     }
     // If the server URL has a user then attempt to use basic authentication.
     if (isset($uri['user'])) {
         $options['headers']['Authorization'] = 'Basic ' . base64_encode($uri['user'] . (isset($uri['pass']) ? ':' . $uri['pass'] : ':'));
     }
     // If the database prefix is being used by SimpleTest to run the tests in a copied
     // database then set the user-agent header to the database prefix so that any
     // calls to other Drupal pages will run the SimpleTest prefixed database. The
     // user-agent is used to ensure that multiple testing sessions running at the
     // same time won't interfere with each other as they would if the database
     // prefix were stored statically in a file or database variable.
     $test_info =& $GLOBALS['drupal_test_info'];
     if (!empty($test_info['test_run_id'])) {
         $options['headers']['User-Agent'] = drupal_generate_test_ua($test_info['test_run_id']);
     }
     $request = $options['method'] . ' ' . $path . " HTTP/1.0\r\n";
     foreach ($options['headers'] as $name => $value) {
         $request .= $name . ': ' . trim($value) . "\r\n";
     }
     $request .= "\r\n" . $options['data'];
     $result->request = $request;
     // Calculate how much time is left of the original timeout value.
     $timeout = $options['timeout'] - bimserverJsonConnector::timer_read(__FUNCTION__) / 1000;
     if ($timeout > 0) {
         stream_set_timeout($fp, floor($timeout), floor(1000000 * fmod($timeout, 1)));
         fwrite($fp, $request);
     }
     // Fetch response. Due to PHP bugs like http://bugs.php.net/bug.php?id=43782
     // and http://bugs.php.net/bug.php?id=46049 we can't rely on feof(), but
     // instead must invoke stream_get_meta_data() each iteration.
     $info = stream_get_meta_data($fp);
     $alive = !$info['eof'] && !$info['timed_out'];
     $response = '';
     while ($alive) {
         // Calculate how much time is left of the original timeout value.
         $timeout = $options['timeout'] - bimserverJsonConnector::timer_read(__FUNCTION__) / 1000;
         if ($timeout <= 0) {
             $info['timed_out'] = TRUE;
             break;
         }
         stream_set_timeout($fp, floor($timeout), floor(1000000 * fmod($timeout, 1)));
         $chunk = fread($fp, 1024);
         $response .= $chunk;
         $info = stream_get_meta_data($fp);
         $alive = !$info['eof'] && !$info['timed_out'] && $chunk;
     }
开发者ID:EVersluys,项目名称:bim4nonbim,代码行数:67,代码来源:bimserverJsonConnector.class.php


注:本文中的drupal_generate_test_ua函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。