我有一個有趣的問題,設置一個cookie,然後在mod_perl下重定向。到目前爲止,我已經有了一個常規的cgi環境,並且設置的cookie /重定向從來都不是問題;一切都按預期工作。然而,當我打開mod_perl時,我得到了一個狀態200和一個html正文與重定向url一起發送。即使我在重定向之前打印它,cookie始終放在標題之後和文檔正文之前。我下調腳本裸機所以你可以看到我的意思:Set-Cookie然後重定向perl CGI下的工作,但不是mod_perl
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI;
my $cgi = new CGI;
my $cookie = CGI::cookie(
'-name' => 'joe',
'-value' => 'fred',
'-path' => '/cgi-bin',
'-httponly' => 1,
);
print "Set-Cookie: $cookie\n";
print $cgi->redirect(-uri => 'http://example.com/cgi-bin/joe.cgi', -status => 303);
當我測試這與在普通CGI嫋嫋,我得到(域名更換,剪斷爲了簡潔):
< HTTP/1.1 303 See Other
< Date: Tue, 23 Oct 2012 16:26:55 GMT
< Server: Apache/2.2.22 (Ubuntu)
< Set-Cookie: joe=fred; path=/cgi-bin; HttpOnly
< Location: http://example.com/cgi-bin/joe.cgi
< Content-Length: 0
......這是我所期望的。當我測試這個mod_perl下,我得到:
< HTTP/1.1 200 OK
< Date: Tue, 23 Oct 2012 16:26:38 GMT
< Server: Apache/2.2.22 (Ubuntu)
< Location: http://example.com/cgi-bin/joe.cgi
< Transfer-Encoding: chunked
<
Set-Cookie: joe=fred; path=/cgi-bin; HttpOnly
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The answer to your request is located <a href="http://example.com/cgi-bin/joe.cgi">here</a>.</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at example.com Port 80</address>
</body></html>
我越來越日誌中沒有任何警告。任何想法爲什麼mod_perl已決定以這種奇怪的方式處理這個重定向?
mod_perl/2.0.5,Apache/2.2.22 – mvsjes2
*你是如何在mod_perl下運行的?您是使用ModPerl :: Registry還是直接運行處理程序? – friedo
您是否看到過有關cookies/redirect的頁面? http://perl.apache.org/docs/2.0/user/coding/cooking.html#Sending_Cookies_in_REDIRECT_Response__ModPerl__Registry_根據您的實施風格顯示cookie /重定向的多種方式。 – mrk