Matthew,
I had to change it a bit again because it would never match if you don't pass in a URI.
class Site_Request extends Zend_Controller_Request_Http
{
public function setRequestUri($requestUri = null)
{
if(null === $requestUri) {
parent::setRequestUri($requestUri);
}
if (isset($_SERVER['HTTP_HOST']) && preg_match('#^([a-z][a-z0-9+.-]+):(//)?(.*?@)?' . preg_quote($_SERVER['HTTP_HOST']) . '#i', $this->_requestUri)) {
$this->_requestUri = substr($this->_requestUri, strpos($this->_requestUri, $_SERVER['HTTP_HOST']) + strlen($_SERVER['HTTP_HOST']));
}
return $this;
}
}
Now it only gets called when the URI is null.
Cheers!
Jon Whitcraft
Indianapolis Motor Speedway
jwhitcraft@brickyard.com
Phone: (317) 492-8623 :: Fax: (317) 492-6419
-----Original Message-----
From: Matthew Weier O'Phinney [mailto:matthew@zend.com]
Sent: Thursday, October 02, 2008 11:22 AM
To: fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] RE: Possible Bug in Zend_Controller_Request_Http
-- Whitcraft, Jon <jwhitcraft@Brickyard.com> wrote
(on Thursday, 02 October 2008, 11:04 AM -0400):
> So do something like this?
>
> require_once ('Zend/Controller/Request/Http.php');
>
> class Site_Request extends Zend_Controller_Request_Http
> {
> public function __construct($uri = null)
> {
> parent::__construct($uri);
> }
constructor won't be necessary; you can inherit that.
> public function setRequestUri($requestUri = null)
> {
>
> parent::setRequestUri($requestUri);
>
> if (isset($_SERVER['HTTP_HOST']) && preg_match('#^([a-z][a-z0-9+.-]+):(//)?(.*?@)?' . preg_quote($_SERVER['HTTP_HOST']) . '#i', $this->_requestUri)) {
> $this->_requestUri = substr($this->_requestUri, strpos($_SERVER['HTTP_HOST']) + strlen($_SERVER['HTTP_HOST']));
> }
>
> return $this;
> }
I'd change the above slightly:
public function setRequestUri($requestUri = null)
{
if (isset($_SERVER['HTTP_HOST']) && preg_match('#^([a-z][a-z0-9+.-]+):(//)?(.*?@)?' . preg_quote($_SERVER['HTTP_HOST']) . '#i', $this->_requestUri)) {
$this->_requestUri = substr($this->_requestUri, strpos($_SERVER['HTTP_HOST']) + strlen($_SERVER['HTTP_HOST']));
} else {
parent::setRequestUri($requestUri);
}
return $this;
}
This way you can move between environments more easily, and not call the
parent method unless you're not actually matching the host.
> }
>
> That seems to work just fine. Thanks for the pointer Matthew.
Cool -- glad I could help. Feel free to propose this addition to ZF; it
may have us to others utilizing proxies or behind firewalls.
> -----Original Message-----
> From: Matthew Weier O'Phinney [mailto:matthew@zend.com]
> Sent: Thursday, October 02, 2008 10:37 AM
> To: Whitcraft, Jon; fw-mvc@lists.zend.com
> Subject: Re: [fw-mvc] RE: Possible Bug in Zend_Controller_Request_Http
>
> -- Whitcraft, Jon <jwhitcraft@Brickyard.com> wrote
> (on Thursday, 02 October 2008, 09:29 AM -0400):
> > Ok so I have created a test case for this and a patch to fix the problem.
> > Please let me know what everyone thinks and I will create an issue and then
> > submit the patch once it gets approved.
>
> Okay, I see a problem with the patch.
>
> Consider the following REQUEST_URI:
>
> /user/login?redirect=http://example.com/foo/bar
>
> Your patch would match the host in this case.
>
> A better check would be a regexp that checks for a scheme:
>
> if (preg_match('#^([a-z][a-z0-9+.-]+):(//)?(.*?@)?' . preg_quote($host) . '#i', $uri)) {
> // matches
> }
>
> I'm still unsure this should be part of the standard request object,
> however, as it's an edge case. It'd be trivial to create a custom
> request object that simply overrides the setRequestUri() method to
> accomplish this.
>
>
> > From: Whitcraft, Jon [mailto:jwhitcraft@Brickyard.com]
> > Sent: Thursday, October 02, 2008 8:59 AM
> > To: fw-mvc@lists.zend.com
> > Subject: [fw-mvc] Possible Bug in Zend_Controller_Request_Http
> >
> >
> >
> > So here's the back story.
> >
> >
> >
> > We are setting up our dev server to be more secure. Meaning that we are going
> > to have to use ssh to port forward a port in so we can view our dev sites.
> > Which is no big deal and it make it more secure. What I'm having a problem
> > with is that our zf based sites are not working with giving me this error:
> >
> >
> >
> > exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid
> > controller specified (http:)' in /var/www/html/zend/zf-1.6.0/Zend/Controller/
> > Dispatcher/Standard.php:249
> >
> > Stack trace:
> >
> > #0 /var/www/html/zend/zf-1.6.0/Zend/Controller/Front.php(946):
> > Zend_Controller_Dispatcher_Standard->dispatch(Object
> > (Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
> >
> > #1 /var/www/html/ims/500/application/library/Site/App.php(171):
> > Zend_Controller_Front->dispatch()
> >
> > #2 /var/www/html/ims/500/index.php(9): Site_App->startMvc()
> >
> > #3 {main}
> >
> >
> >
> > The request object looks like this when it gets to the dispatch object:
> >
> >
> >
> >
> >
> > Zend_Controller_Request_Http Object
> >
> > (
> >
> > [_paramSources:protected] => Array
> >
> > (
> >
> > [0] => _GET
> >
> > [1] => _POST
> >
> > )
> >
> >
> >
> > [_requestUri:protected] => http://dev.indy500.com/
> >
> > [_baseUrl:protected] =>
> >
> > [_basePath:protected] =>
> >
> > [_pathInfo:protected] => http://dev.indy500.com/
> >
> > [_params:protected] => Array
> >
> > (
> >
> > [controller] => http:
> >
> > [] => dev.indy500.com
> >
> > [action] => index
> >
> > [module] => default
> >
> > )
> >
> >
> >
> > [_aliases:protected] => Array
> >
> > (
> >
> > )
> >
> >
> >
> > [_dispatched:protected] => 1
> >
> > [_module:protected] => default
> >
> > [_moduleKey:protected] => module
> >
> > [_controller:protected] => http:
> >
> > [_controllerKey:protected] => controller
> >
> > [_action:protected] => index
> >
> > [_actionKey:protected] => action
> >
> > )
> >
> >
> >
> >
> >
> > Now the problem I'm having is that using the port forwarding this way makes the
> > Request Http object think that the requestURI is http://dev.indy500.com instead
> > of / like it does when I'm not using port forwarding.
> >
> >
> >
> > Would it be possible to have it when it set's the requestURI to make sure it
> > doesn't contain any of the host name?
> >
> >
> >
> > http:// Jon Whitcraft
> > www.whitcraftconsulting.com Indianapolis Motor Speedway
> > /images/ jwhitcraft@brickyard.com
> > php5_zce_logo_new.gif
> > P: (317) 492-8623 - F: (317) 492-6419
> >
> >
> >
> >
> >
> >
> > ********************
> > ********************
> > This E-mail (and attachments) may contain confidential/privileged information
> > intended only for the named addressee(s). If you are not an intended recipient,
> > do not read, copy, disseminate or take any action based on the content of this
> > E-mail. Please notify the sender by reply E-mail and erase this E-mail from
> > your system. Your assistance is appreciated. E-mail transmission may not be
> > secure or error-free. The company is not responsible for any loss/damage
> > arising from any virus transmitted.
> > ********************
> > ********************
> >
>
>
>
>
>
> --
> Matthew Weier O'Phinney
> Software Architect | matthew@zend.com
> Zend Framework | http://framework.zend.com/
>
>
> ********************
> ********************
> This E-mail (and attachments) may contain confidential/privileged information intended only for the named addressee(s). If you are not an intended recipient, do not read, copy, disseminate or take any action based on the content of this E-mail. Please notify the sender by reply E-mail and erase this E-mail from your system. Your assistance is appreciated. E-mail transmission may not be secure or error-free. The company is not responsible for any loss/damage arising from any virus transmitted.
> ********************
> ********************
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
2008年10月2日星期四
订阅:
博文评论 (Atom)
没有评论:
发表评论