$t->is($request->getUriPrefix(), 'https://symfony-project.org', '->getUriPrefix() returns no port for standard https port'); $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $t->is($request->getUriPrefix(), 'https://symfony-project.org', '->getUriPrefix() works fine with no port in HTTP_HOST'); $_SERVER['HTTP_HOST'] = 'symfony-project.org:8043'; $t->is($request->getUriPrefix(), 'https://symfony-project.org:8043', '->getUriPrefix() works for nonstandard https ports'); $request->resetPathInfoArray(); $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $_SERVER['SERVER_PORT'] = '8080'; $t->is($request->getUriPrefix(), 'http://symfony-project.org:8080', '->getUriPrefix() uses the "SERVER_PORT" environment variable'); $request->resetPathInfoArray(); $_SERVER['HTTPS'] = 'on'; $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $_SERVER['SERVER_PORT'] = '8043'; $t->is($request->getUriPrefix(), 'https://symfony-project.org:8043', '->getUriPrefix() uses the "SERVER_PORT" environment variable'); $request->resetPathInfoArray(); $request->setOption('http_port', '8080'); $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $t->is($request->getUriPrefix(), 'http://symfony-project.org:8080', '->getUriPrefix() uses the configured port'); $request->setOption('http_port', null); $request->resetPathInfoArray(); $request->setOption('https_port', '8043'); $_SERVER['HTTPS'] = 'on'; $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $t->is($request->getUriPrefix(), 'https://symfony-project.org:8043', '->getUriPrefix() uses the configured port'); $request->setOption('https_port', null); $request->resetPathInfoArray(); $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'; $t->is($request->getUriPrefix(), 'https://symfony-project.org', '->getUriPrefix() works on secure requests forwarded as non-secure requests'); $request->resetPathInfoArray();
// ->getContentType() $t->diag('->getContentType()'); $request = new myRequest($dispatcher); $_SERVER['CONTENT_TYPE'] = 'text/html'; $t->is($request->getContentType(), 'text/html', '->getContentType() returns the content type'); $request = new myRequest($dispatcher); $_SERVER['CONTENT_TYPE'] = 'text/html; charset=UTF-8'; $t->is($request->getContentType(), 'text/html', '->getContentType() strips the charset information by default'); $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'); // ->getReferer() $t->diag('->getReferer()'); $request = new myRequest($dispatcher); $_SERVER['HTTP_REFERER'] = 'http://domain'; $t->is($request->getReferer(), 'http://domain', '->getContentType() returns the content type'); // ->getHost() $t->diag('->getHost()'); $request = new myRequest($dispatcher); $_SERVER['HTTP_X_FORWARDED_HOST'] = 'example1.com, example2.com, example3.com'; $t->is($request->getHost(), 'example3.com', '->getHost() returns the last forwarded host'); unset($_SERVER['HTTP_X_FORWARDED_HOST']); $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $t->is($request->getHost(), 'symfony-project.org', '->getHost() returns the host'); $request->setOption('trust_proxy', false); $_SERVER['HTTP_X_FORWARDED_HOST'] = 'example1.com, example2.com, example3.com'; $t->is($request->getHost(), 'symfony-project.org', '->getHost() returns the host even if forwarded host is define when "trust_proxy" option is set to false'); unset($_SERVER['HTTP_X_FORWARDED_HOST']); // ->getFiles() $t->diag('->getFiles()'); $_FILES = array('article' => array('name' => array('media' => '1.png'), 'type' => array('media' => 'image/png'), 'tmp_name' => array('media' => '/private/var/tmp/phpnTrAJG'), 'error' => array('media' => 0), 'size' => array('media' => 899))); $taintedFiles = array('article' => array('media' => array('error' => 0, 'name' => '1.png', 'type' => 'image/png', 'tmp_name' => '/private/var/tmp/phpnTrAJG', 'size' => 899))); $t->is_deeply($request->getFiles(), $taintedFiles, '->getFiles() return clean array extracted from $_FILES');