Bug 49308 - many mod_headers response header treatments do not work for file and cgi content
Summary: many mod_headers response header treatments do not work for file and cgi content
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Documentation (show other bugs)
Version: 2.2.15
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: HTTP Server Documentation List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-18 13:28 UTC by Alain Knaff
Modified: 2010-05-29 08:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alain Knaff 2010-05-18 13:28:53 UTC
When used together with file content (index.html) or CGI, mod_headers behaves as if its response header treatment runs _before_ content generation, and not afterwards.

"set", "append" and "merge" behave like "add", adding another instance of a header, instead of replacing (or appending to) it (... because I suppose, it actually runs before the script, so it "sets" the header, and then the script "adds" his)

"edit", "unset" don't do anything at all (because, they run before the script, and thus have nothing to work on).

This is observed over a wide range of Apache versions, and can be seen on 2.2.8, 2.2.11, 2.2.14 and 2.2.15

However, if 2 Header directives are present operating on the same header, then the second does operate correctly on the result left by the first.

Test case:

index.cgi

#!/bin/sh

echo Content-Type: text/plain
echo Test-set: a1
echo Test-append: b1
echo Test-edit: c1
echo Test-merge: d1
echo Test-add: e1
echo Test-unset: f1
echo
echo xyz


.htaccess:

Options +ExecCGI
AddHandler cgi-script .cgi

Header set Test-set a2
Header append Test-append b2
Header edit Test-edit c xx1
Header add Test-add e2
Header unset Test-unset
Header append Test-double-append g1
Header append Test-double-append g2

Output (of curl -D - http://localhost/~alain/header/index.cgi):

HTTP/1.1 200 OK
Date: Tue, 18 May 2010 17:25:41 GMT
Server: Apache/2.2.14 (Ubuntu)
Test-set: a1
Test-append: b1
Test-edit: c1
Test-merge: d1
Test-add: e1
Test-unset: f1
Test-set: a2
Test-append: b2
Test-merge: d1
Test-add: e2
Test-double-append: g1, g2
Transfer-Encoding: chunked
Content-Type: text/plain

xyz


Expected:

HTTP/1.1 200 OK
Date: Tue, 18 May 2010 17:25:41 GMT
Server: Apache/2.2.14 (Ubuntu)
Test-set: a2
Test-append: b1, b2
Test-edit: xx11
Test-merge: d1
Test-add: e1
Test-add: e2
Test-double-append: g1, g2
Transfer-Encoding: chunked
Content-Type: text/plain

xyz
Comment 1 Ruediger Pluem 2010-05-19 02:11:13 UTC
IMHO this doesn't sound like a bug but more like a question for the users support mailing list. Have you tried using the header directive outside the .htaccess file in the main configuration?
Comment 2 Alain Knaff 2010-05-19 02:17:40 UTC
Yes, I've also tried it within a <Directory> section in a file in /etc/apache2 : same reaction.
Comment 3 Pablo Garcia 2010-05-20 08:36:10 UTC
I've run into the same issue,
I've tried allways with the directives within the config, unsign mod_headers as a module and compiled into httpd, with the same result.
Using php on my side.
Is there any debug option I can enable to provide more information ?

Regards, Pablo
Comment 4 Eric Covener 2010-05-20 08:59:45 UTC
"A value of always  may be needed to influence headers set by some internal modules even for successful responses, and is always needed to affect non-2xx  responses such as redirects or client errors."

This is the case for headers set by CGI.
Comment 5 Eric Covener 2010-05-20 09:14:53 UTC
doc updated to emphasize that CGI's are effectively set by one of those internal modules. While technically Apache knows if the CGI returned a 2xx by the time it saves the headers, it always saves them in the "always" bucket (err_headers_out)

please ACK that this resolves the problem
Comment 6 Alain Knaff 2010-05-20 13:40:42 UTC
Yes, that does indeed solve the problem, thanks.

Header always edit Cache-control no-cache "private, max-age=0"
Comment 7 Alain Knaff 2010-05-29 08:06:41 UTC
Interestingly enough, when using ProxyPass, the behaviour is just the opposite:

Header (without always) works, but "Header always" doesn't.