Discussion:
CGI : Mojolicious::Lite renders http headers when running with $app->start('cgi')
(too old to reply)
Revlin John
2013-04-21 20:58:06 UTC
Permalink
Hi,

Probably not many are running Mojolicious as a CGI script, but I'm testing
it out on a LAMP server with Firefox as my client. Here's the script:

#!/usr/bin/perl
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Mojolicious::Lite;
my $app = app;
my $version = Mojolicious->VERSION;
get '/' => sub {
$self->render( inline => <<HTML );
<!DOCTYPE html>
<html><head>
<title>Mojolicious Title App</title>
</head>
<body>
Mojolicious: $version <br />
</body></html>
HTML
};
$app->start('cgi');
And here's what I see in my browser:

Content-Type: text/html;charset=UTF-8
X-Powered-By: Mojolicious (Perl)
Status: 200 OK
Date: Sun, 21 Apr 2013 20:50:41 GMT
Content-Length: 137

<!DOCTYPE html>
<html><head>
<title>Mojolicious Title App</title>
</head>
<body>
Mojolicious: 2.23 <br />
Reading:
</body></html>


So, somehow the http headers are not being treated as headers by the
client, but rather plain text which is rendered on screen. How do I fix
this?

Thanks,
Rev
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Sebastian Riedel
2013-04-21 21:04:55 UTC
Permalink
Post by Revlin John
Mojolicious: 2.23 <br />
That version of Mojolicious is from 2011.

--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us
Revlin John
2013-04-21 21:34:08 UTC
Permalink
Thanks, Sebastian.

I also had a 'say' statement in there which I didn't include in my example
get routine. I think that was breaking the response header process when
running as CGI.
How can I detect whether the runtime environment is CGI or Morbo?

The following works fine once I comment out the say statements, even with
my old-arse release of Mojolicious:

get '/' => sub {
my $self = shift;
# Some host environment info is modeled by Mojo::Message::Request
# which I guess is intended to emulate the HTTP request process
my $req = $self->req;
# $req can now be used to access other objects like header, url,
# running Mojolicious within a CGI environment [ with app->start('cgi') ]
my $URL = $req->url; # now we should be able to display parts of the
URL...
#say $URL;
#say $URL->host;
my $base_url = $URL->base;
my $mojoENV = ( join "\n<br />", sort keys %{$req->env} );
#2) How to use inline text to "render" HTML
$self->render( inline => <<HTML );
<!DOCTYPE html>
<html><head>
<title>Mojolicious Title App</title>
</head>
<body>
Mojolicious: $version <br />
Reading: $base_url <br />
ENV Vars: $mojoENV
</body></html>
HTML
};
Post by Revlin John
Mojolicious: 2.23 <br />
That version of Mojolicious is from 2011.
--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Tekki
2013-05-06 19:16:38 UTC
Permalink
I also had a 'say' statement in there ...
"say" prints to STDOUT, which in CGI mode is the browser. Where do you want
to print these informations to?
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Revlin John
2013-05-06 20:38:07 UTC
Permalink
Hi Tekki,

Originally, to the console or STDOUT, when the script was running in morbo.
This thread is just my process of realizing that if I want to take a
Mojolicious program that was previously running in morbo and have it run in
CGI instead, I have to comment out all the stuff that was previously
printing to STDOUT or STDERR.

Thanks,
Rev
Post by Tekki
I also had a 'say' statement in there ...
"say" prints to STDOUT, which in CGI mode is the browser. Where do you
want to print these informations to?
--
You received this message because you are subscribed to a topic in the
Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/mojolicious/grivePrVtMg/unsubscribe?hl=en
.
To unsubscribe from this group and all its topics, send an email to
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
***@gmail.com
stylogicalmaps.blogspot.com
dream, play and have fun.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Sebastian Riedel
2013-05-06 21:04:18 UTC
Permalink
I have to comment out all the stuff that was previously printing to STDOUT or STDERR.
This is why there's a logger built-in, i've just updated the tutorial with some more information on how to use it.

http://mojolicio.us/perldoc/Mojolicious/Lite#Mode

--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us
Revlin John
2013-05-06 21:40:23 UTC
Permalink
Awesome! Now I'll have to go back through my scripts and start using this.
Great update to the guides.

Rev
Post by Revlin John
I have to comment out all the stuff that was previously printing to
STDOUT or STDERR.
This is why there's a logger built-in, i've just updated the tutorial with
some more information on how to use it.
http://mojolicio.us/perldoc/Mojolicious/Lite#Mode
--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us
--
You received this message because you are subscribed to a topic in the
Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/mojolicious/grivePrVtMg/unsubscribe?hl=en
.
To unsubscribe from this group and all its topics, send an email to
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
***@gmail.com
stylogicalmaps.blogspot.com
dream, play and have fun.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Charlie Brady
2013-05-08 17:36:37 UTC
Permalink
Post by Revlin John
Hi Tekki,
Originally, to the console or STDOUT, when the script was running in morbo.
This thread is just my process of realizing that if I want to take a
Mojolicious program that was previously running in morbo and have it run in
CGI instead, I have to comment out all the stuff that was previously
printing to STDOUT or STDERR.
No, not STDERR. Anything printed to STDERR will be saved in the web
server's error log - or at least, it will with apache.
Post by Revlin John
Thanks,
Rev
Post by Tekki
I also had a 'say' statement in there ...
"say" prints to STDOUT, which in CGI mode is the browser. Where do you
want to print these informations to?
--
You received this message because you are subscribed to a topic in the
Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/mojolicious/grivePrVtMg/unsubscribe?hl=en
.
To unsubscribe from this group and all its topics, send an email to
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Revlin John
2013-05-08 17:57:31 UTC
Permalink
Thanks for the tip, Charlie, but have you tried running a Mojolicious CGI
script that prints to STDERR?
Just want to make sure that's tested before putting it out there.

Peace,
Rev




On Wed, May 8, 2013 at 10:36 AM, Charlie Brady <
Post by Revlin John
Post by Revlin John
Hi Tekki,
Originally, to the console or STDOUT, when the script was running in
morbo.
Post by Revlin John
This thread is just my process of realizing that if I want to take a
Mojolicious program that was previously running in morbo and have it run
in
Post by Revlin John
CGI instead, I have to comment out all the stuff that was previously
printing to STDOUT or STDERR.
No, not STDERR. Anything printed to STDERR will be saved in the web
server's error log - or at least, it will with apache.
Post by Revlin John
Thanks,
Rev
Post by Tekki
I also had a 'say' statement in there ...
"say" prints to STDOUT, which in CGI mode is the browser. Where do you
want to print these informations to?
--
You received this message because you are subscribed to a topic in the
Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/mojolicious/grivePrVtMg/unsubscribe?hl=en
Post by Revlin John
Post by Tekki
.
To unsubscribe from this group and all its topics, send an email to
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the
Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/mojolicious/grivePrVtMg/unsubscribe?hl=en
.
To unsubscribe from this group and all its topics, send an email to
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
***@gmail.com
stylogicalmaps.blogspot.com
dream, play and have fun.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Revlin John
2013-05-06 18:50:21 UTC
Permalink
I just added a full post about this issue to http://uni-sol.ca/my-mojo/?p=41

Peace,
Rev
Post by Revlin John
Hi,
Probably not many are running Mojolicious as a CGI script, but I'm testing
#!/usr/bin/perl
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Mojolicious::Lite;
my $app = app;
my $version = Mojolicious->VERSION;
get '/' => sub {
$self->render( inline => <<HTML );
<!DOCTYPE html>
<html><head>
<title>Mojolicious Title App</title>
</head>
<body>
Mojolicious: $version <br />
</body></html>
HTML
};
$app->start('cgi');
Content-Type: text/html;charset=UTF-8
X-Powered-By: Mojolicious (Perl)
Status: 200 OK
Date: Sun, 21 Apr 2013 20:50:41 GMT
Content-Length: 137
<!DOCTYPE html>
<html><head>
<title>Mojolicious Title App</title>
</head>
<body>
Mojolicious: 2.23 <br />
</body></html>
So, somehow the http headers are not being treated as headers by the
client, but rather plain text which is rendered on screen. How do I fix
this?
Thanks,
Rev
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Continue reading on narkive:
Loading...