Re: [Catalyst] hostname
On Thursday 10 January 2008 21:15:25 Octavian Rasnita wrote: From: Ash Berlin [EMAIL PROTECTED] How did you get to a function in MyApp.pm during a request # in MyApp.pm sub foobarbaz { my ($c) = @_; } # In controller code. $c-foobarbaz(); Make sense? Not really. I've tried (in MyApp.pm): sub the_host { my ($c) = @_; return $c-req-hostname; } and then I've tried to use cookie_domain = the_host() in the MyApp config, but when I try to start the server it gives an error telling that I can't use the method req because $c is undefined. You could use MyApp::Root::auto to lookup the hostname from the request and set it in config as you wish. Example: # MyApp::Root; sub auto : Private { my ( $self, $c ) = @_; $c-config-{cookie_domain} = $c-req-hostname; } But anyway, what I need is working because I can avoid setting a domain name for the cookie. Octavian ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ -- Knut-Olav Hoven Systemutvikler mob: +47 986 71 700 Linpro AShttp://www.linpro.no/ signature.asc Description: This is a digitally signed message part. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
cookie_domain = the_host() in the MyApp config, but when I try to start the server it gives an error telling that I can't use the method req because $c is undefined. I'd be curious about why you wanted the cookie domain in the config anyway! I presume you've got a bit of code like: $c-response-cookies-{'foo'} = { domain = $c-config('cookie_domain') }; In which case why couldn't you just do $c-response-cookies-{'foo'} = { domain = $c-req-hostname }; But anyway, what I need is working because I can avoid setting a domain name for the cookie. Yeah exactly, setting the domain in the cookie to match the domain requested is pretty pointless anyway as that's what browsers do by default. About the only time you need to send a domain back is when you want to set a cookie across all subdomains or similar. Eg: { domain = '.example.com' } Carl ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
From: Carl Johnstone [EMAIL PROTECTED] cookie_domain = the_host() in the MyApp config, but when I try to start the server it gives an error telling that I can't use the method req because $c is undefined. I'd be curious about why you wanted the cookie domain in the config anyway! I presume you've got a bit of code like: $c-response-cookies-{'foo'} = { domain = $c-config('cookie_domain') }; In which case why couldn't you just do $c-response-cookies-{'foo'} = { domain = $c-req-hostname }; I needed the domain name for setting the session in MyApp.pm. Octavian ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
On Jan 11, 2008, at 5:29 AM, Carl Johnstone wrote: cookie_domain = the_host() in the MyApp config, but when I try to start the server it gives an error telling that I can't use the method req because $c is undefined. I'd be curious about why you wanted the cookie domain in the config anyway! I think the idea was something along the lines of... MyApp-config-{ 'session' }-{ 'cookie_domain' } = MyApp-request- header-( 'host' ); I presume you've got a bit of code like: $c-response-cookies-{'foo'} = { domain = $c- config('cookie_domain') }; In which case why couldn't you just do $c-response-cookies-{'foo'} = { domain = $c-req-hostname }; But anyway, what I need is working because I can avoid setting a domain name for the cookie. Yeah exactly, setting the domain in the cookie to match the domain requested is pretty pointless anyway as that's what browsers do by default. About the only time you need to send a domain back is when you want to set a cookie across all subdomains or similar. Eg: { domain = '.example.com' } In which case you could still do something in Root/auto if you wanted to modify it... my $domain_re = join( '|', qw( mydomain.com myotherdomain.com foo.com example.com ) ); sub auto : Private { my ( $self, $c ) = @_; if ( $c-request-header( 'host' ) =~ /(\.(?:$domain_re))$/ ) { $c-config-{ 'session' }-{ 'cookie_domain' } = $1; } return 1; } -- Jason Kohles, RHCA RHCDS RHCE [EMAIL PROTECTED] - http://www.jasonkohles.com/ A witty saying proves nothing. -- Voltaire ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
from the context object, but is unavailable to MyApp.pm. cookie_domain Both the context object and the hostname should be available to code within MyApp.pm, but only if the code is running during a request. In any case I wouldn't point multiple domains at the same site, you're always best off choosing your preferred name and redirecting alternatives. Otherwise you're going to have fun with users following links to domain1.com and coming back via links to domain2.com - often within minutes of each other. That said, there's a case for needing to know the hostname if you've got multiple sites running from the same Cat App. Carl ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
Carl Johnstone [EMAIL PROTECTED] wrote on 01/10/2008 09:44:30 AM: from the context object, but is unavailable to MyApp.pm. cookie_domain Both the context object and the hostname should be available to code within MyApp.pm, but only if the code is running during a request. In any case I wouldn't point multiple domains at the same site, you're always best off choosing your preferred name and redirecting alternatives. Otherwise you're going to have fun with users following links to domain1.com and coming back via links to domain2.com - often within minutes of each other. How would you propose handling an ASP like service that is branded (both host whatever.companya.com ... othersuch.company9.com, and templates) for 1 companies? 1 instances of your app on different servers + all of the cache and proxy services? Or would you have companya.com redirect to service.aspprovider.com and lose the ability (and pretty important branding sometimes) to masquerade the service as if it were run by companya? I am just saying, it is a completely valid and useful ability. -Wade That said, there's a case for needing to know the hostname if you've got multiple sites running from the same Cat App. Carl ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
On Jan 10, 2008, at 1:54 PM, Octavian Rasnita wrote: From: Carl Johnstone [EMAIL PROTECTED] Both the context object and the hostname should be available to code within MyApp.pm, but only if the code is running during a request. Ok, but how to get the hostname during a request in MyApp.pm if a $c variable is not available? What you seem to be missing is that (in the current version at least) MyApp *IS* $c. package MyApp; sub get_hostname { my ( $self ) = @_; return $self-request-header( 'host' ); } -- Jason Kohles, RHCA RHCDS RHCE [EMAIL PROTECTED] - http://www.jasonkohles.com/ A witty saying proves nothing. -- Voltaire ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
From: [EMAIL PROTECTED] Sys::Hostname or a statically set config var, as there is no reference to a request at that point (or any real way to derive the list of possible hostnames hat could be requested). But then again, unless you know the hostname that will always be requested why try to set it at that point at all? I would still opt for using the request to set a dynamic hostname later in the process unless you have good reason not to (ssl cert tied to a hostname for example). I think most times it is better to not assume that the hostname requested will be static in code. It makes for a more flexible and deployment easier for your app (do you really want to go change a hardcoded hostname when dns changes need to happen). Yes, these days we've just made some changes including DNS changes and for a few days we will have a temporary address for internal use, just a public IP, and I hope as soon as possible we've have a real address working and I would like to make all those ways of accessing the server work. You said that I could make those settings later. Did I understand correctly that I could re-write that config settings in the Root.pm controller for making it available to all the controllers? It could be helpful for other things, because for this problem I learned that I can simply avoid setting a domain for the cookie. Octavian ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
On Jan 10, 2008, at 3:15 PM, Octavian Rasnita wrote: From: Ash Berlin [EMAIL PROTECTED] How did you get to a function in MyApp.pm during a request # in MyApp.pm sub foobarbaz { my ($c) = @_; } # In controller code. $c-foobarbaz(); Make sense? Not really. I've tried (in MyApp.pm): sub the_host { my ($c) = @_; return $c-req-hostname; } and then I've tried to use cookie_domain = the_host() in the MyApp config, but when I try to start the server it gives an error telling that I can't use the method req because $c is undefined. Because you didn't define it. You have to call it as a method ($c- the_host()), and you have to call it *during a request*. I don't know how you still expect to be able to get a value that is sent by the browser during startup when there is no browser. -- Jason Kohles, RHCA RHCDS RHCE [EMAIL PROTECTED] - http://www.jasonkohles.com/ A witty saying proves nothing. -- Voltaire ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
On Jan 9, 2008, at 6:16 AM, Octavian Rasnita wrote: Is it possible to get the host name in MyApp.pm just like I can do it in a controller using $c-req-hostname; I want to use the current hostname for setting the cookie in the session, and the site could be accessed with 2 or more different host names. If I hard-code a certain hostname, the login won't work on other host names. $c-req-hostname doesn't return the server hostname, it returns the client hostname. Can't the current host that was requested be accessed in MyApp.pm? $c-req-header( 'Host' ); -- Jason Kohles, RHCA RHCDS RHCE [EMAIL PROTECTED] - http://www.jasonkohles.com/ A witty saying proves nothing. -- Voltaire ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
Ash Berlin [EMAIL PROTECTED] wrote on 01/09/2008 05:39:22 AM: On Jan 9, 2008, at 11:12 AM, Octavian Rasnita wrote: From: Ashley [EMAIL PROTECTED] Oh, I was too fast. Blush. You mean without the context object. :( Yes, that's what I want. Can't the context object be accessed in MyApp.pm? Thanks. Octavian Currently MyApp.pm *is* the context object. The problem is Catalyst has no idea of the hostname until it sees the request headers - you can have multiple hosts point at the same Catalyst app. Only you know what the hostname is - so you'll have to set it in the config. -ash Not really, the http request also includes the clients version of the host it is requesting from. This is how virtual servers work (where one http process serves different data based on the hostname the client is requesting). $c-req-header( 'Host' ) provides the information needed from the context object, but is unavailable to MyApp.pm. cookie_domain setting in Catalyst::Plugin::Session::State::Cookie needs to be set to reflect the requested hostname in this case else the browser will not set the cookie nor include it on round trips to the application if the requested host/domain is different from the host that Catalyst believes it is running as. I believe a workaround for this issue is to leave the cookie_domain setting unset which I believe will produce a cookie that is not stating its domain and the client browser will treat as locked to the requested host's name for the domain. So if you want the cookie to be set on the client without worrying about the hostname requested don't set the domain_name or set the domain_name to the common domain for all hosts. -Wade ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] hostname
If you mean to get hostname in offline mode (off the processing request) - the hostname is not known because there are no request. You can get the server's real hostname by Sys::Hostname::hostname() but this probably won't help. 2008/1/9, Octavian Rasnita [EMAIL PROTECTED]: Hi, Is it possible to get the host name in MyApp.pm just like I can do it in a controller using $c-req-hostname; Thank you. Octavian ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/