Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Changing http headers in cgi response

by Your Mother (Archbishop)
on Aug 25, 2010 at 22:15 UTC ( [id://857320]=note: print w/replies, xml ) Need Help??


in reply to Changing http headers in cgi response

Don't do that ("break the web"). If it's not there, 404 is appropriate. If you mean it be a 302 or maybe better a 301 (202 doesn't make sense here), then you should do a 302. Don't serve the content from the correct URI under the 404. Your webserver layer is the most efficient way to do this when possible (path translation, etc). Otherwise something along the lines of-

use CGI qw(:standard); use URI; my $new = URI->new(url()); $new->path("/some/new/place"); print redirect($new); # 302 by default. exit 0;

Replies are listed 'Best First'.
Re^2: Changing http headers in cgi response
by twotone (Beadle) on Sep 10, 2010 at 05:16 UTC

    Hmmm... It seems I wasn't clear enough in my question. I'm not trying to return Status 202 OK when the content isn't found. I'm just not wanting to create (let's say 50) identical cgi scripts for the 50 "virtual" pages I have in my database. I want to display any of those 50 pages by using only 1 script. The page would be chosen based on the URL content after the domain like this: domain.com/page/to/look/up/in/database/. So that when that page content is FOUND in the database, the content is returned with status 202.

    This would be a the process step by step:

    • Page is requested: doman.com/requested/page/
    • My script is registered as custom 404 handler
    • script does database query for requested/page/
    • if found, requested/page/ is returned with 202 OK
    • if not, 404 not found is returned
    I set up a drupal site once on a server that didn't do url rewriting and this was exactly the way drupal did it. I just don't remember if it modified the 404 status to 202.

    SO, can any one tell me how to change the 404 status header to 202 when I send back the found page?

      I think you might be unclear what 202 means(?). It's not for "content" at all. It's for saying, "I got your request and I'll look into it and let you know; maybe here's a link or something you so you can check back when I'm ready with what you actually asked for."

      You are trying to overload your web server to behave as your dispatcher. Don't do it. Use proper dispatch and server configuration. Here is an example (untested—pasted from a web sample—and might need correction) configuration for apache to point to a script (fastcgi in this case but CGI should work too)-

      RewriteEngine On RewriteRule ^(/somedir/dispatch\.fcgi/.*)$ - [L] RewriteRule ^(.*)$ somedir/dispatch.fcgi/$1 [PT,L]

      Then you can use the request URI (everything in the path after the script's name) inside your (F)CGI to do the things you're talking about wanting to do while returning proper status codes to match.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://857320]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found