Re: Should I just print my own HTTP headers?
by ambrus (Abbot) on Apr 05, 2007 at 08:06 UTC
|
You can. Just take care of that you have to output CGI headers, not http headers. This means in practice that you do not have to print a http status line (the one with a three-digit number), instead the webserver will print one as approperiate (200 normally, 302 in case you print a Location header so the server thinks it's a redirect), and that the server will correct the line endings of your header to crlfs. (Update: the server will also do the chunked encoding if you don't specify the Content-length, do the keepalive connection, and lots of other magical stuff I can't even imagine.)
The only header you are required to print is Content-type. Just search perlmonks for "Content-type", and you'll find lots of examples. (In case you wanted to write http requests by hand, you can do that too: in that case the only required header is Host.)
Update: it seems I didn't answer your question. Well, the CGI module does not output any headers, so it is safe to use it just the input part.
| [reply] [Watch: Dir/Any] |
Re: Should I just print my own HTTP headers?
by zer (Deacon) on Apr 05, 2007 at 06:29 UTC
|
as long as it is simple requests it shouldnt be a problem
incoming headers tend to be more complicated from a cgi perspected if there is posted data, which cgi.pm takes care of quite nicely. But if it is basic get stuff it is pretty straight forward parsing.
As for outgoing. There is nothing to it. Just take note of syntax esp if youre doing cookies or other meta headers
the w3c can help you if you get jammed
w3c on HTTP
| [reply] [Watch: Dir/Any] |
Re: Should I just print my own HTTP headers?
by samtregar (Abbot) on Apr 05, 2007 at 17:08 UTC
|
I'm sure you've heard this a million times: CGI.pm is big and I don't want to use it.
Yup, and every time I hear it it sounds pretty foolish. CGI.pm may be big, but it uses Autoloader extensively to avoid memory bloat. And if you've got a modern Perl you don't even have to download it, it's a standard module! So just use it already! In the time it took you to ask this question you could be done already, not to mention dealing with parsing parameters.
-sam
| [reply] [Watch: Dir/Any] |
|
True, but even ignoring the Autoloader stuff, it's still 800+ lines of code that has to be loaded to accomplish something that would probably take me around 10.
| [reply] [Watch: Dir/Any] |
|
You make it sound like you're going to load those lines of code with your bare hands in an ice storm. Trust me, this is not the bottleneck you're looking for! I've profiled a lot of slow web-apps in my day and I've never once seen a CGI.pm method in the top 10.
-sam
| [reply] [Watch: Dir/Any] |
|
|
|
|
|
|
|
|
|
|
|
You might be better off using CGI.pm to get started, and then later on if loading the 800+ lines appears to be a problem, replace it with your 10 lines. That way you only have to write one line now: "use CGI;", and you'll be able to look at the HTML source being produced so that you know exactly what you need to replace it with, if you still want to.
| [reply] [Watch: Dir/Any] |
Re: Should I just print my own HTTP headers?
by naikonta (Curate) on Apr 13, 2007 at 02:14 UTC
|
| [reply] [Watch: Dir/Any] |
|
Well, it should only be run via a mod_rewrite rule, but it's easy enough to double check:
if ($ENV{'QUERY_STRING'} !~ /^\d{,10}$/) {
die 'Invalid ID';
}
| [reply] [Watch: Dir/Any] [d/l] |