當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::setTrustedHeaderName方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\Request::setTrustedHeaderName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::setTrustedHeaderName方法的具體用法?PHP Request::setTrustedHeaderName怎麽用?PHP Request::setTrustedHeaderName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\Request的用法示例。


在下文中一共展示了Request::setTrustedHeaderName方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSetTrustedProxiesInvalidHeaderName

 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetTrustedProxiesInvalidHeaderName()
 {
     Request::create('http://example.com/');
     Request::setTrustedHeaderName('bogus name', 'X_MY_FOR');
 }
開發者ID:anderson-abc,項目名稱:sf2_kowee,代碼行數:8,代碼來源:RequestTest.php

示例2: testTrustedProxies

 public function testTrustedProxies()
 {
     $request = Request::create('http://example.com/');
     $request->server->set('REMOTE_ADDR', '3.3.3.3');
     $request->headers->set('X_FORWARDED_FOR', '1.1.1.1, 2.2.2.2');
     $request->headers->set('X_FORWARDED_HOST', 'foo.example.com, real.example.com:8080');
     $request->headers->set('X_FORWARDED_PROTO', 'https');
     $request->headers->set('X_FORWARDED_PORT', 443);
     $request->headers->set('X_MY_FOR', '3.3.3.3, 4.4.4.4');
     $request->headers->set('X_MY_HOST', 'my.example.com');
     $request->headers->set('X_MY_PROTO', 'http');
     $request->headers->set('X_MY_PORT', 81);
     // no trusted proxies
     $this->assertEquals('3.3.3.3', $request->getClientIp());
     $this->assertEquals('example.com', $request->getHost());
     $this->assertEquals(80, $request->getPort());
     $this->assertFalse($request->isSecure());
     // disabling proxy trusting
     Request::setTrustedProxies(array());
     $this->assertEquals('3.3.3.3', $request->getClientIp());
     $this->assertEquals('example.com', $request->getHost());
     $this->assertEquals(80, $request->getPort());
     $this->assertFalse($request->isSecure());
     // trusted proxy via setTrustedProxies()
     Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
     $this->assertEquals('1.1.1.1', $request->getClientIp());
     $this->assertEquals('real.example.com', $request->getHost());
     $this->assertEquals(443, $request->getPort());
     $this->assertTrue($request->isSecure());
     // custom header names
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X_MY_FOR');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X_MY_HOST');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_MY_PORT');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_MY_PROTO');
     $this->assertEquals('4.4.4.4', $request->getClientIp());
     $this->assertEquals('my.example.com', $request->getHost());
     $this->assertEquals(81, $request->getPort());
     $this->assertFalse($request->isSecure());
     // disabling via empty header names
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, null);
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, null);
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, null);
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, null);
     $this->assertEquals('3.3.3.3', $request->getClientIp());
     $this->assertEquals('example.com', $request->getHost());
     $this->assertEquals(80, $request->getPort());
     $this->assertFalse($request->isSecure());
     // reset
     Request::setTrustedProxies(array());
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X_FORWARDED_FOR');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X_FORWARDED_HOST');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_FORWARDED_PORT');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO');
 }
開發者ID:Werelds,項目名稱:FrameworkBenchmarks,代碼行數:54,代碼來源:RequestTest.php

示例3: testESIHeaderIsKeptInSubrequestWithTrustedHeaderDisabled

 public function testESIHeaderIsKeptInSubrequestWithTrustedHeaderDisabled()
 {
     $trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, '');
     $this->testESIHeaderIsKeptInSubrequest();
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
 }
開發者ID:scrobot,項目名稱:Lumen,代碼行數:7,代碼來源:InlineFragmentRendererTest.php

示例4: getenv

<?php

use Shopware\Components\HttpCache\AppCache;
use Symfony\Component\HttpFoundation\Request;
/**
 * @var Composer\Autoload\ClassLoader
 */
$loader = (require __DIR__ . '/../app/autoload.php');
$environment = getenv('SHOPWARE_ENV');
$kernel = new AppKernel($environment, $environment !== 'production');
if ($kernel->isHttpCacheEnabled()) {
    $kernel = new AppCache($kernel, $kernel->getHttpCacheConfig());
}
$request = Request::createFromGlobals();
// Trust the heroku load balancer
// see: https://devcenter.heroku.com/articles/getting-started-with-symfony#trusting-the-load-balancer
Request::setTrustedProxies([$request->server->get('REMOTE_ADDR')]);
Request::setTrustedHeaderName(Request::HEADER_FORWARDED, null);
$response = $kernel->handle($request);
$response->send();
開發者ID:bcremer,項目名稱:shopware-composer-project,代碼行數:20,代碼來源:index.php


注:本文中的Symfony\Component\HttpFoundation\Request::setTrustedHeaderName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。