New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Phalcon\Http\Request #11921

Merged
merged 7 commits into from Jun 26, 2016

Conversation

Projects
None yet
1 participant
@sergeyklay
Member

sergeyklay commented Jun 23, 2016

  • 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 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 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