A question about add_header replication

by bit bullon 2009-10-05T08:29:16+00:00
hi,all:
hello, I config "add_header Server xxxx;", then I get response header:
< HTTP/1.1 200 OK
< Server: nginx/0.8.17
< Date: Mon, 05 Oct 2009 07:59:18 GMT
< Content-Type: text/html
< Content-Length: 151
< Last-Modified: Mon, 05 Oct 2009 07:24:51 GMT
< Connection: keep-alive
< Server: xxxx
< Accept-Ranges: bytes
We can see Server field is printed twice. I need replace first one.
So I read source code, found:
1.add_header is simple push to header_out array, keep
headers_out.server == NULL.
2. "Server:nginx/0.8.17" field is setted at http_header_filter_module.c:457
3. a loop start at http_header_filter_module.c:568, it concat all
header fields(include "Server xxxx").
4. Server field is replication.
why not set headers_out.server at add_header? how to implement my need?
sorry for my poor english.
thanks
bb

Re: A question about add_header replication

by Maxim Douninon 2009-10-05T16:10:56+00:00.
Hello!
On Mon, Oct 05, 2009 at 04:11:53PM +0800, bit bull wrote:
> hi,all:
>
> hello, I config "add_header Server xxxx;", then I get response header:
>
> < HTTP/1.1 200 OK
> < Server: nginx/0.8.17
> < Date: Mon, 05 Oct 2009 07:59:18 GMT
> < Content-Type: text/html
> < Content-Length: 151
> < Last-Modified: Mon, 05 Oct 2009 07:24:51 GMT
> < Connection: keep-alive
> < Server: xxxx
> < Accept-Ranges: bytes
>
> We can see Server field is printed twice. I need replace first one.
>
> So I read source code, found:
>
> 1.add_header is simple push to header_out array, keep
> headers_out.server == NULL.
> 2. "Server:nginx/0.8.17" field is setted at http_header_filter_module.c:457
> 3. a loop start at http_header_filter_module.c:568, it concat all
> header fields(include "Server xxxx").
> 4. Server field is replication.
>
> why not set headers_out.server at add_header? how to implement my need?
1. Directive add_header does not support arbitrary header rewriting.
2. No, you can't redefine Server header without patching code. It
isn't considered to be good thing to do, but for those who still
thinks that hiding head in sand is a good way to handle security
there is directive "server_tokens off;" which will hide version
string from Server header and standard error pages.
Maxim Dounin

Re: A question about add_header replication

by bit bullon 2009-10-05T17:21:31+00:00.
1. why not support any header rewriting? I think this feature will
make a flexible config-file.
2. I used "server_tokens off;". thanks
2009/10/5 Maxim Dounin :
>
> 1. Directive add_header does not support arbitrary header rewriting.
>
> 2. No, you can't redefine Server header without patching code. =A0It
> isn't considered to be good thing to do, but for those who still
> thinks that hiding head in sand is a good way to handle security
> there is directive "server_tokens off;" which will hide version
> string from Server header and standard error pages.
>
> Maxim Dounin
>
>

Re: A question about add_header replication

by agentzhon 2009-10-06T01:38:03+00:00.
On Tue, Oct 6, 2009 at 1:03 AM, bit bull wrote:
> 1. why not support any header rewriting? =A0I think this feature will
> make a flexible config-file.
> 2. I used =A0"server_tokens off;". =A0thanks
>
Well, this could be easily done by a custom C module (implemented as
an output header filter perhaps). I'm pondering writing a Headers-More
module, which will also provide an option to manipulate headers of
pages with 4xx and 5xx status codes.
Cheers,
-agentzh

Re: A question about add_header replication

by bit bullon 2009-10-06T12:32:05+00:00.
thanks for your help~ Headers-More module looks very useful.
2009/10/6 agentzh :
> On Tue, Oct 6, 2009 at 1:03 AM, bit bull wrote:
>> 1. why not support any header rewriting? =A0I think this feature will
>> make a flexible config-file.
>> 2. I used =A0"server_tokens off;". =A0thanks
>>
>
> Well, this could be easily done by a custom C module (implemented as
> an output header filter perhaps). I'm pondering writing a Headers-More
> module, which will also provide an option to manipulate headers of
> pages with 4xx and 5xx status codes.
>
> Cheers,
> -agentzh
>
>

Re: A question about add_header replication

by agentzhon 2009-10-07T02:39:45+00:00.
On Tue, Oct 6, 2009 at 8:10 PM, bit bull wrote:
> thanks for your help~ Headers-More module looks very useful.
>
I'll look into it after I finished my nginx-echo-module in the next
few days. I'd also turn it into a patch to the standard headers module
if Igor and others like it.
Stay tuned!
-agentzh

Re: A question about add_header replication

by bit bullon 2009-10-07T05:58:07+00:00.
I think Igor and others will like it.haha~
BTW: What's the echo-module?
2009/10/7 agentzh :
> On Tue, Oct 6, 2009 at 8:10 PM, bit bull wrote:
>> thanks for your help~ Headers-More module looks very useful.
>>
>
> I'll look into it after I finished my nginx-echo-module in the next
> few days. I'd also turn it into a patch to the standard headers module
> if Igor and others like it.
>
> Stay tuned!
> -agentzh
>
>

Re: A question about add_header replication

by agentzhon 2009-10-08T02:43:12+00:00.
On Wed, Oct 7, 2009 at 1:42 PM, bit bull wrote:
> I think Igor and others will like it.haha~
>
:)
> BTW: What's the echo-module?
>
A simple module that lets nginx to echo things directly just like a
classic CGI script (but without CGI or Perl of course):
http://github.com/agentzh/echo-nginx-module
Currently only "echo" and "echo_client_request_headers" directives are
supported. I'm working on "echo_sleep" (a non-blocking sleep on the
server side) directively atm. "echo_location" and filter versions of
"echo_before_body" and "echo_after_body" are also on my TODO list.
Cheers,
-agentzh

Re: A question about add_header replication

by bit bullon 2009-10-09T03:51:14+00:00.
oh~so interesting!
2009/10/8 agentzh :
> On Wed, Oct 7, 2009 at 1:42 PM, bit bull wrote:
>> I think Igor and others will like it.haha~
>>
>
> :)
>
>> BTW: What's the echo-module?
>>
>
> A simple module that lets nginx to echo things directly just like a
> classic CGI script (but without CGI or Perl of course):
>
> =A0 http://github.com/agentzh/echo-nginx-module
>
> Currently only "echo" and "echo_client_request_headers" directives are
> supported. I'm working on "echo_sleep" (a non-blocking sleep on the
> server side) directively atm. "echo_location" and filter versions of
> "echo_before_body" and "echo_after_body" are also on my TODO list.
>
> Cheers,
> -agentzh
>
>

Re: A question about add_header replication

by agentzhon 2009-11-17T09:31:12+00:00.
On Mon, Oct 5, 2009 at 4:11 PM, bit bull wrote:
> hi,all:
>
> =A0 =A0hello, I config "add_header Server xxxx;", then I get response hea=
der:
>
> < HTTP/1.1 200 OK
> < Server: nginx/0.8.17
> < Date: Mon, 05 Oct 2009 07:59:18 GMT
> < Content-Type: text/html
> < Content-Length: 151
> < Last-Modified: Mon, 05 Oct 2009 07:24:51 GMT
> < Connection: keep-alive
> < Server: xxxx
> < Accept-Ranges: bytes
>
> We can see Server field is printed twice. I need replace first one.
The "more_set_headers" of the "headers_more" module will work the way
that you expect now:
more_set_headers 'Server: xxxx';
Also, it applies to all the status code by default, unlike the
standard "headers" module. Use the -s option of the "more_set_headers"
directive if you want more control over it ;)
See http://github.com/agentzh/headers-more-nginx-module for more details.
Cheers,
-agentzh