From 35bfcd1d3203ac97befce5b250766d1d21ab851b Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Tue, 13 Feb 2018 17:46:26 +0100
Subject: [PATCH] handle headers from perl code, not templates

---
 lib/AccountManager/WebRequest.pm      | 5 +++++
 t/account-manager.cgi.t               | 4 ++--
 templates/web/index-nobanner.tt2.html | 3 ---
 templates/web/index.tt2.html          | 3 ---
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/AccountManager/WebRequest.pm b/lib/AccountManager/WebRequest.pm
index ebee8ea..5b2a270 100644
--- a/lib/AccountManager/WebRequest.pm
+++ b/lib/AccountManager/WebRequest.pm
@@ -164,6 +164,11 @@ sub respond {
 
     binmode(STDOUT, ":utf8");
 
+    print $self->{cgi}->header(
+        -type    => 'text/html',
+        -charset => ''
+    );
+
     unless ($tt2->process($template, $self->{out}, \*STDOUT)) {
         printf "Content-type: text/plain\n\n Error: %s", $tt2->error();
         $self->{logger}->errorf("Web parser error : %s", $tt2->error());
diff --git a/t/account-manager.cgi.t b/t/account-manager.cgi.t
index aba7bd9..8a75704 100755
--- a/t/account-manager.cgi.t
+++ b/t/account-manager.cgi.t
@@ -23,7 +23,7 @@ subtest start_page => sub {
     diag($out) if $ENV{TEST_DEBUG};
     like(
         $out,
-        qr{^Content-Type: text/html\n\n},
+        qr{^Content-Type: text/html\r\n\r\n},
         'HTTP headers'
     );
     like(
@@ -50,7 +50,7 @@ subtest sp_selection_page => sub {
     diag($out) if $ENV{TEST_DEBUG};
     like(
         $out,
-        qr{^Content-Type: text/html\n\n},
+        qr{^Content-Type: text/html\r\n\r\n},
         'HTTP headers'
     );
     like(
diff --git a/templates/web/index-nobanner.tt2.html b/templates/web/index-nobanner.tt2.html
index 5d42fb6..8006d7f 100644
--- a/templates/web/index-nobanner.tt2.html
+++ b/templates/web/index-nobanner.tt2.html
@@ -1,6 +1,3 @@
-Content-Type: text/html
-[% IF cookie %]Set-Cookie: [% cookie %][% END %]
-
 <?xml version="1.0" encoding="utf-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/x
 html1/DTD/xhtml1-transitional.dtd">
 
diff --git a/templates/web/index.tt2.html b/templates/web/index.tt2.html
index 161613e..53fce36 100644
--- a/templates/web/index.tt2.html
+++ b/templates/web/index.tt2.html
@@ -1,6 +1,3 @@
-Content-Type: text/html
-[% IF cookie %]Set-Cookie: [% cookie %][% END %]
-
 <?xml version="1.0" encoding="utf-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/x
 html1/DTD/xhtml1-transitional.dtd">
 <html xml:lang="[% iso639 = locale.match('^(.)(.)'); iso639.0; iso639.1 %]" xmlns="http://www.w3.org/1999/xhtml">
-- 
GitLab