Hi, Per the docs for 1.1805, I can work with the env vars as follows -- in my App.pm ------------ my $env = request->env(); template <tmpl>, { var1 => $env->{var1}, var2 => $env->{var2} .. and so on .. } in my template -------------- var1: [% var1 %]<br /> var2: [% var2 %]<br /> .. and so on .. The above is not working for me as I am trying to use basic Apache env vars such as REQUEST_URI, SCRIPT_FILENAME, etc. A little background, since someone might be able to suggest a different way of accomplishing what I am trying to do -- My web site is at http://mywebsite.org/. In the VirtualHost definition of mywebsite.org, I have the following ProxyPass /app/one http://one.org/ ProxyPassReverse /app/one http://one.org/ Of course, http://one.org/ is a Dancer application. So, when the users go to http://mywebsite.org/ they see the regular, static web site. However, when they go to http://mywebsite.org/app/one/ they see my Dancer web site. In order to get the correct paths to the CSS and images and other assets for one.org, I need that '/app/one' bit from the request uri. That way I can do the following in my template <link rel="stylesheet" href="[% uri %]/css/grid.css" /> The reason I can't hard code the above is because there are more than one applications, and, of course, I want to be able to access the application directly from http://one.org/ as well. Suggestions on how I can grab the requested uri? -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
On 2010-08-19, at 9:18 AM, P Kishor wrote:
Suggestions on how I can grab the requested uri?
Have you tried request->path ? Best, Olaf -- Olaf Alders olaf@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct)
On Thu, Aug 19, 2010 at 9:21 AM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 9:18 AM, P Kishor wrote:
Suggestions on how I can grab the requested uri?
Have you tried request->path ?
I had not, but I just did, and that kinda worked, but not really. Let me explain. As I explained in my original post, I am using a proxy to access the Dancer app. In my Apache conf file, I have the following ProxyPass /app/one http://one.org/ ProxyPassReverse /app/one http://one.org/ So, when the address in the browser URL bar is http://mywebsite/app/one, the Dancer app is actually getting http://one.org/ In other words, when the user requests http://mywebsite/app/one, Dancer's request->path() is simply '/' instead of '/app/one' I am hoping to be able to use other Apache variables to grab this, but request->env() doesn't seem to be working. Could it be that request->env() grabs CGI env variables, and since I am using Plack::Handler::Apache2, it is not really CGI that I am using. Any other suggestions?
Best,
Olaf -- Olaf Alders olaf@wundersolutions.com
http://www.wundersolutions.com http://twitter.com/wundercounter
866 503 2204 (Toll free - North America) 416 944 8306 (direct)
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
On 2010-08-19, at 10:32 AM, P Kishor wrote:
On Thu, Aug 19, 2010 at 9:21 AM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 9:18 AM, P Kishor wrote:
Suggestions on how I can grab the requested uri?
Have you tried request->path ?
I had not, but I just did, and that kinda worked, but not really. Let me explain.
As I explained in my original post, I am using a proxy to access the Dancer app. In my Apache conf file, I have the following
ProxyPass /app/one http://one.org/ ProxyPassReverse /app/one http://one.org/
So, when the address in the browser URL bar is http://mywebsite/app/one, the Dancer app is actually getting http://one.org/
In other words, when the user requests http://mywebsite/app/one, Dancer's request->path() is simply '/' instead of '/app/one'
I am hoping to be able to use other Apache variables to grab this, but request->env() doesn't seem to be working. Could it be that request->env() grabs CGI env variables, and since I am using Plack::Handler::Apache2, it is not really CGI that I am using.
Any other suggestions?
As far as your setup goes, you may want to at least consider something like this: http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and... "The environment variables such as PATH_INFO and SCRIPT_NAME are automatically adjusted so it just works like when your application is mounted using Apache's mod_alias or CGI scripts. Your application framework should always use PATH_INFO to dispatch requests, and concatenate with SCRIPT_NAME to build links." This should get you pretty much to the same place, but with the added advantage of being able to use Plack's debug panels etc. Hope this helps, Olaf -- Olaf Alders olaf@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct)
On Thu, Aug 19, 2010 at 12:41 PM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 10:32 AM, P Kishor wrote:
On Thu, Aug 19, 2010 at 9:21 AM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 9:18 AM, P Kishor wrote:
Suggestions on how I can grab the requested uri?
Have you tried request->path ?
I had not, but I just did, and that kinda worked, but not really. Let me explain.
As I explained in my original post, I am using a proxy to access the Dancer app. In my Apache conf file, I have the following
ProxyPass /app/one http://one.org/ ProxyPassReverse /app/one http://one.org/
So, when the address in the browser URL bar is http://mywebsite/app/one, the Dancer app is actually getting http://one.org/
In other words, when the user requests http://mywebsite/app/one, Dancer's request->path() is simply '/' instead of '/app/one'
I am hoping to be able to use other Apache variables to grab this, but request->env() doesn't seem to be working. Could it be that request->env() grabs CGI env variables, and since I am using Plack::Handler::Apache2, it is not really CGI that I am using.
Any other suggestions?
As far as your setup goes, you may want to at least consider something like this:
http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and...
"The environment variables such as PATH_INFO and SCRIPT_NAME are automatically adjusted so it just works like when your application is mounted using Apache's mod_alias or CGI scripts. Your application framework should always use PATH_INFO to dispatch requests, and concatenate with SCRIPT_NAME to build links."
This should get you pretty much to the same place, but with the added advantage of being able to use Plack's debug panels etc.
Hope this helps,
wow! That Plack advent calendar is brilliant. I am learning a lot from it, however, I am not sure it helps me. Since I am already using Dancer, I am "supposed" to be shielded from dealing with Plack directly, no? In other words, (from the quote above), Dancer should give me access to PATH_INFO and SCRIPT_NAME, etc. Which is precisely what I want. -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
On 2010-08-19, at 3:27 PM, P Kishor wrote:
As far as your setup goes, you may want to at least consider something like this:
http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and...
"The environment variables such as PATH_INFO and SCRIPT_NAME are automatically adjusted so it just works like when your application is mounted using Apache's mod_alias or CGI scripts. Your application framework should always use PATH_INFO to dispatch requests, and concatenate with SCRIPT_NAME to build links."
This should get you pretty much to the same place, but with the added advantage of being able to use Plack's debug panels etc.
Hope this helps,
wow! That Plack advent calendar is brilliant. I am learning a lot from it, however, I am not sure it helps me. Since I am already using Dancer, I am "supposed" to be shielded from dealing with Plack directly, no? In other words, (from the quote above), Dancer should give me access to PATH_INFO and SCRIPT_NAME, etc. Which is precisely what I want.
Could you post a dump of your request->env ? -- Olaf Alders olaf@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct)
On Thu, Aug 19, 2010 at 5:09 PM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 3:27 PM, P Kishor wrote:
As far as your setup goes, you may want to at least consider something like this:
http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and...
"The environment variables such as PATH_INFO and SCRIPT_NAME are automatically adjusted so it just works like when your application is mounted using Apache's mod_alias or CGI scripts. Your application framework should always use PATH_INFO to dispatch requests, and concatenate with SCRIPT_NAME to build links."
This should get you pretty much to the same place, but with the added advantage of being able to use Plack's debug panels etc.
Hope this helps,
wow! That Plack advent calendar is brilliant. I am learning a lot from it, however, I am not sure it helps me. Since I am already using Dancer, I am "supposed" to be shielded from dealing with Plack directly, no? In other words, (from the quote above), Dancer should give me access to PATH_INFO and SCRIPT_NAME, etc. Which is precisely what I want.
Could you post a dump of your request->env ?
this may sound very dumb, but I frankly don't know how to dump a data structure. How do I dump the entire request->env()? -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
On Thu, Aug 19, 2010 at 7:20 PM, P Kishor <punk.kish@gmail.com> wrote:
On Thu, Aug 19, 2010 at 5:09 PM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 3:27 PM, P Kishor wrote:
As far as your setup goes, you may want to at least consider something like this:
http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and...
"The environment variables such as PATH_INFO and SCRIPT_NAME are automatically adjusted so it just works like when your application is mounted using Apache's mod_alias or CGI scripts. Your application framework should always use PATH_INFO to dispatch requests, and concatenate with SCRIPT_NAME to build links."
This should get you pretty much to the same place, but with the added advantage of being able to use Plack's debug panels etc.
Hope this helps,
wow! That Plack advent calendar is brilliant. I am learning a lot from it, however, I am not sure it helps me. Since I am already using Dancer, I am "supposed" to be shielded from dealing with Plack directly, no? In other words, (from the quote above), Dancer should give me access to PATH_INFO and SCRIPT_NAME, etc. Which is precisely what I want.
Could you post a dump of your request->env ?
this may sound very dumb, but I frankly don't know how to dump a data structure. How do I dump the entire request->env()?
ok, figured it out. I set log level to debug, and then wrote debug to_dumper(request->env()) which gave me the following $VAR1 = { 'psgi.multiprocess' => 1, 'SCRIPT_NAME' => '', 'PATH_INFO' => '/', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'REQUEST_METHOD' => 'GET', 'psgi.multithread' => '', 'SCRIPT_FILENAME' => '/Users/punkish/Sites/lca/', 'SERVER_SOFTWARE' => 'Apache/2.2.16 (Unix) DAV/2 mod_perl/2.0.4 Perl/v5.12.1', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8', 'REMOTE_PORT' => '60500', 'QUERY_STRING' => '', 'SERVER_SIGNATURE' => '', 'HTTP_CACHE_CONTROL' => 'max-age=0', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'HTTP_KEEP_ALIVE' => '115', 'psgi.streaming' => 1, 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'MOD_PERL_API_VERSION' => '2', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'psgi.version' => [ 1, 1 ], 'DOCUMENT_ROOT' => '/Users/punkish/Sites/lca', 'psgi.run_once' => '', 'UNIQUE_ID' => 'TG3RfsCoAWcAAPtoA2EAAAAJ', 'SERVER_NAME' => 'lca.local', 'SERVER_ADMIN' => 'punkish@eidesis.org', 'HTTP_ACCEPT_ENCODING' => 'gzip,deflate', 'HTTP_CONNECTION' => 'keep-alive', 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'psgi.errors' => *::STDERR, 'REQUEST_URI' => '/', 'psgi.nonblocking' => '', 'SERVER_ADDR' => '127.0.0.1', 'psgi.url_scheme' => 'http', 'HTTP_HOST' => 'lca.local', 'MOD_PERL' => 'mod_perl/2.0.4', 'psgi.input' => bless( do{\(my $o = 4305081000)}, 'Apache2::RequestRec' ) }; in /Users/punkish/Sites/lca/lib/lca.pm l. 10 -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
On 2010-08-19, at 8:52 PM, P Kishor wrote:
ok, figured it out. I set log level to debug, and then wrote
debug to_dumper(request->env())
What do you get if you comment out ProxyPassReverse in your Apache config and restart Apache? -- Olaf Alders olaf@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct)
On Thu, Aug 19, 2010 at 8:02 PM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 8:52 PM, P Kishor wrote:
ok, figured it out. I set log level to debug, and then wrote
debug to_dumper(request->env())
What do you get if you comment out ProxyPassReverse in your Apache config and restart Apache?
Olaf, Thanks a ton for holding my hand. I figured out a solution for my dilemma. First, basically, as far as Apache is concerned, the proxied request is as if it were made directly. In other words, if I have the following ProxyPass /app/foo http://foo.org Apache thinks I have actually called http://foo.org directly when I actually go to http://mywebsite/app/foo. So, none of the URI values are sent to the forwarded host. Also, as far as I can see, no other env variables are passed on as well, EXCEPT! ... If I use Proxy, the following setting appears in my env variables: 'HTTP_X_FORWARDED_SERVER' So, I can detect that value, and set my uri appropriately like so url => request->env()->{HTTP_X_FORWARDED_SERVER} ? '/app/foo' : '', Too bad I can't pass variables from one server to another, but hey, the above works, so I can move on to the next task. Many thanks for your help and perseverance. -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
P Kishor <punk.kish@gmail.com> writes:
On Thu, Aug 19, 2010 at 8:02 PM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 8:52 PM, P Kishor wrote:
[...]
Thanks a ton for holding my hand. I figured out a solution for my dilemma. First, basically, as far as Apache is concerned, the proxied request is as if it were made directly. In other words, if I have the following
ProxyPass /app/foo http://foo.org
Apache thinks I have actually called http://foo.org directly when I actually go to http://mywebsite/app/foo.
...which, indeed, you just did. The fact that your proxy passes the content and some headers back to the originator is invisible to the endpoints. To address this you have a handful of choices: You can, if you have a sufficiently recent Apache, use the HTML/XML rewriting module that works in conjunction with the proxy to rewrite URL paths on the way out in the body, not just the headers. You can make your back-end server use the same paths as the front-end server, so that the environment is uniform. You can use a protocol like FastCGI rather than HTTP between your front-end server and your application server. Since that does preserve, and pass, the original path details where HTTP doesn't your back-end will get what you want. In our company we use the later two options, but prefer the FastCGI approach. Having that listen via TCP works great, and it also opens the door to later using a lighter weight server than Apache at the front end. Regards, Daniel -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons
On 2010-08-19, at 8:20 PM, P Kishor wrote:
On Thu, Aug 19, 2010 at 5:09 PM, Olaf Alders <olaf@wundersolutions.com> wrote:
On 2010-08-19, at 3:27 PM, P Kishor wrote:
As far as your setup goes, you may want to at least consider something like this:
http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and...
"The environment variables such as PATH_INFO and SCRIPT_NAME are automatically adjusted so it just works like when your application is mounted using Apache's mod_alias or CGI scripts. Your application framework should always use PATH_INFO to dispatch requests, and concatenate with SCRIPT_NAME to build links."
This should get you pretty much to the same place, but with the added advantage of being able to use Plack's debug panels etc.
Hope this helps,
wow! That Plack advent calendar is brilliant. I am learning a lot from it, however, I am not sure it helps me. Since I am already using Dancer, I am "supposed" to be shielded from dealing with Plack directly, no? In other words, (from the quote above), Dancer should give me access to PATH_INFO and SCRIPT_NAME, etc. Which is precisely what I want.
Could you post a dump of your request->env ?
this may sound very dumb, but I frankly don't know how to dump a data structure. How do I dump the entire request->env()?
One simple way would be to add the following to your Dancer app: use Data::Dump qw( dump ); get '/env' => sub { return '<pre>' . dump( \%ENV ) . '<hr>' . dump( request->env ) . '</pre>'; }; Then, go to /env in your app and copy/paste the output. You'll find that %ENV != request->env, but they probably both (hopefully) have the info you might need. -- Olaf Alders olaf@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct)
participants (3)
-
Daniel Pittman -
Olaf Alders -
P Kishor