Welcome! Log In Create A New Profile

Advanced

Re: ngx_http_send_special_response

Maxim Dounin
April 16, 2012 06:38AM
Hello!

On Mon, Apr 16, 2012 at 01:53:39AM -0700, hagai avrahami wrote:

>
>
> Hi
>
> I am appreciate any help I can get on the following issues.
>
> I am writing my own module.
>
> 1. I can see in function ngx_http_send_special_response
>     that it calculates the content length of the error page even if the request signed as header only (r->header_only = 1)
>     and set the content length header with value, after sending the header it does not send the body ( because  r->header_only = 1)
>     so the response arrive with content length different than 0 but without body
>
>     Is it a BUG?

No. The r->header_only flag should is set when body isn't
expected per protocol (HEAD requests, 304 responses). Having
Content-Length present in such responses is ok.

> 2.In the module I am trying to redirect the request with status code 302 (NGX_HTTP_MOVED_TEMPORARILY)
>    Trying to user->headers_out.location for the Alternate URL failed, I looked in the code and saw the Location must start with "/" - why?

You have to set it correctly, i.e. add to r->headers_out.headers
and link to r->headers_out.location. If it starts with "/" it
works even if set incorrectly due to adding of a server_name,
that's probably what confused you.

>    In the end I add it to r->headers_out.headers
>    using header = ngx_list_push(&r->headers_out.headers);
>    Is it the write way to do it?
>
> 3. Can you explain please the different between
>     a. r->headers_out.content_length_n
>     b. r->headers_out.content_length

The content_length_n is a numeric length, this what you normaly
should set when generating response in nginx. The content_length
is a pointer to a headers array element, it might be present if
there is string representation of a Content-Length header
available for some reason (e.g. from a backend).

> 4. Can you explain the usage of the hash field in ngx_table_elt_t

Normally the hash field is used for fast lookups in hash
structures. In case of r->headers_out it's usually just set to 1
indicate the header is valid (or reset to 0 to indicate the
header should not be sent as it was superseeded by some other
header).

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

ngx_http_send_special_response

hagai avrahami April 16, 2012 04:54AM

Re: ngx_http_send_special_response

Maxim Dounin April 16, 2012 06:38AM

Re: ngx_http_send_special_response

hagai avrahami April 16, 2012 07:30AM

Re: ngx_http_send_special_response

Maxim Dounin April 16, 2012 09:40AM

Re: ngx_http_send_special_response

hagai avrahami April 16, 2012 11:16AM

Re: ngx_http_send_special_response

Maxim Dounin April 16, 2012 11:58AM

Re: ngx_http_send_special_response

hagai avrahami April 16, 2012 12:30PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 229
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready