in reply to How redirect the page in CGI programming?

You don't have to use the CGI module for everything. I personally use it only for parsing of the cgi parameters, but rarely for forming a response.

print "Status: 302 Found\n", "Location: http://www.perlmonks.com/\n\n";

Replies are listed 'Best First'.
Re^2: How redirect the page in CGI programming?
by merlyn (Sage) on Jun 21, 2005 at 11:42 UTC
    print "Status: 302 Found\n", "Location: http://www.perlmonks.com/\n\n";
    Well, sure, but technically, if that is being sent directly to the browser (say, from a lightweight server using a direct socket), you need to send "\cM\cJ" not just "\n", according to the RFCs.

    This is why it's better to use CGI.pm... all that stuff just works:

    localhost:~ % perl -MCGI=redirect -e 'print redirect("/somewhere")' | +od -c 0000000 S t a t u s : 3 0 2 M o v + e 0000020 d \r \n L o c a t i o n : / s + o 0000040 m e w h e r e \r \n \r \n + 0000053

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Yes, you are right. It would only work as a CGI. However, the browser has to convert the Status-header to a http status line (such as "HTTP/1.1 302 Found\cm\cj"), as Status is CGI-specific. I don't know how these lightweight servers you mention work, but I suppose either they or the CGI module would have to issue a status line anyway.