Refactored Phalcon\Http\Request #11921

Merged
merged 7 commits into from Jun 26, 2016

Projects

None yet

1 participant

@sergeyklay
Collaborator
sergeyklay commented Jun 23, 2016 edited
  • Now Request::getHttpHost always return host name or empty string
  • Optionally Request::getHttpHost can validate and clean host name
  • Added Request::getPort. To get information about the port on which the request is made
  • Added Request::setStrictHostCheck and Request::isStrictHostCheck to manage strict validation of host name
  • Updated Phalcon\Http\RequestInterface

Request::getHttpHost trying to find host name in following order:

  • $_SERVER['HTTP_HOST']
  • $_SERVER['SERVER_NAME']
  • $_SERVER['SERVER_ADDR']


Note: validation and cleaning has a negative performance impact because they uses regular expressions.

use Phalcon\Http\Request;

$request = new Request;

$_SERVER['HTTP_HOST'] = 'example.com';
$request->getHttpHost(); // example.com

$_SERVER['HTTP_HOST'] = 'example.com:8080';
$request->getHttpHost(); // example.com:8080

$request->setStrictHostCheck(true);
$_SERVER['HTTP_HOST'] = 'ex=am~ple.com';
$request->getHttpHost(); // throws UnexpectedValueException

// The Request::_strictHostCheck is still true
$_SERVER['HTTP_HOST'] = 'ExAmPlE.com';
$request->getHttpHost(); // example.com

$request->setStrictHostCheck(false);
$_SERVER['HTTP_HOST'] = 'ExAmPlE.com';
$request->getHttpHost(); // ExAmPlE.com

Fixes #2573

sergeyklay added some commits Jun 23, 2016
@sergeyklay sergeyklay Fixed Request::getHttpHost 70c52df
@sergeyklay sergeyklay Cleanup Route::handle 8caab8a
@sergeyklay sergeyklay Amended Request::getHttpHost tests 5fb8b49
@sergeyklay sergeyklay Added Request::getPort 44b0839
@sergeyklay sergeyklay changed the title from Refactored Phalcon\Http\Request::getHttpHost to Refactored Phalcon\Http\Request Jun 24, 2016
sergeyklay added some commits Jun 24, 2016
@sergeyklay sergeyklay Added Request::setStrictHostCheck and Request::isStrictHostCheck 6e4fa5b
@sergeyklay sergeyklay Updated Phalcon\Http\RequestIterface a41077f
@sergeyklay sergeyklay Ameded Request tests 0affdb4
@sergeyklay sergeyklay merged commit 2de3c2a into phalcon:2.1.x Jun 26, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment