Development

Changeset 32729 for branches/1.3

You must first sign up to be able to contribute.

Changeset 32729 for branches/1.3

Show
Ignore:
Timestamp:
07/05/11 17:23:04 (3 years ago)
Author:
www-data
Message:

[1.3, 1.4] updated getHost() to consider a chain of forwarded hosts

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/lib/request/sfWebRequest.class.php

    r30900 r32729  
    356356    $pathArray = $this->getPathInfoArray(); 
    357357 
    358     return isset($pathArray['HTTP_X_FORWARDED_HOST']) ? $pathArray['HTTP_X_FORWARDED_HOST'] : (isset($pathArray['HTTP_HOST']) ? $pathArray['HTTP_HOST'] : ''); 
     358    if (isset($pathArray['HTTP_X_FORWARDED_HOST'])) 
     359    { 
     360      $elements = explode(',', $pathArray['HTTP_X_FORWARDED_HOST']); 
     361 
     362      return trim($elements[count($elements) - 1]); 
     363    } 
     364    else 
     365    { 
     366      return isset($pathArray['HTTP_HOST']) ? $pathArray['HTTP_HOST'] : ''; 
     367    } 
    359368  } 
    360369 
  • branches/1.3/test/unit/request/sfWebRequestTest.php

    r30900 r32729  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(71); 
     13$t = new lime_test(72); 
    1414 
    1515class myRequest extends sfWebRequest 
     
    368368$t->is($request->getContentType(), 'text/html', '->getContentType() strips the charset information by default'); 
    369369$t->is($request->getContentType(false), 'text/html; charset=UTF-8', '->getContentType() does not strip the charset information by defaultif you pass false as the first argument'); 
     370 
     371// ->getHost() 
     372$t->diag('->getHost()'); 
     373 
     374$request = new myRequest($dispatcher); 
     375$_SERVER['HTTP_X_FORWARDED_HOST'] = 'example1.com, example2.com, example3.com'; 
     376$t->is($request->getHost(), 'example3.com', '->getHost() returns the last forwarded host'); 
     377unset($_SERVER['HTTP_X_FORWARDED_HOST']);