From 0c75bd00cf14a04c9e750c58f289d8688cb579cc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 31 Jan 2008 11:49:10 +0000 Subject: [PATCH] Das Erzeugen der HTTP-Antwort in eine eigene Funktion ausgelagert, damit sie auch von anderer Stelle aus benutzt werden kann. --- SL/Form.pm | 71 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index 76ae60d77..4caa9b943 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -481,6 +481,48 @@ sub isblank { $main::lxdebug->leave_sub(); } +sub create_http_response { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + my $cgi = $main::cgi; + $cgi ||= CGI->new(''); + + my $base_path; + + if ($ENV{HTTP_X_FORWARDED_FOR}) { + $base_path = $ENV{HTTP_REFERER}; + $base_path =~ s|^.*?://.*?/|/|; + } else { + $base_path = $ENV{REQUEST_URI}; + } + $base_path =~ s|[^/]+$||; + $base_path =~ s|/$||; + + my $session_cookie; + if (defined $main::auth) { + my $session_cookie_value = $main::auth->get_session_id(); + $session_cookie_value ||= 'NO_SESSION'; + + $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(), + '-value' => $session_cookie_value, + '-path' => $base_path); + } + + my %cgi_params = ('-type' => $params{type}); + $cgi_params{'-charset'} = $params{charset} if ($parmas{charset}); + + my $output = $cgi->header('-cookie' => $session_cookie, + %cgi_params); + + $main::lxdebug->leave_sub(); + + return $output; +} + + sub header { $main::lxdebug->enter_sub(); @@ -491,9 +533,6 @@ sub header { return; } - my $cgi = $main::cgi; - $cgi ||= CGI->new(''); - my ($stylesheet, $favicon); if ($ENV{HTTP_USER_AGENT}) { @@ -555,30 +594,8 @@ sub header { $ajax .= $item->show_javascript(); } - my $base_path; - - if ($ENV{HTTP_X_FORWARDED_FOR}) { - $base_path = $ENV{HTTP_REFERER}; - $base_path =~ s|^.*?://.*?/|/|; - } else { - $base_path = $ENV{REQUEST_URI}; - } - $base_path =~ s|[^/]+$||; - $base_path =~ s|/$||; - - my $session_cookie; - if (defined $main::auth) { - my $session_cookie_value = $main::auth->get_session_id(); - $session_cookie_value ||= 'NO_SESSION'; - - $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(), - '-value' => $session_cookie_value, - '-path' => $base_path); - } - - print $cgi->header('-type' => 'text/html', - '-charset' => $db_charset, - '-cookie' => $session_cookie); + print $self->create_http_response('type' => 'text/html', + 'charset' => $db_charset,); print qq|${doctype} $self->{titlebar} -- 2.20.1