<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hi</div><div>Thanks<br>
<br>
The redirect response is from content handler context.</div><div><br></div><div>Using the code you added <br></div><div>cause Nginx to send back the Error Page (302) with Content-Length and Content-Type ("test/html") (And I am trying avoid that) without Body<br></div><div><br></div><div>That's why I assumed using  <span style="font-weight: bold;">r->header_only = 1 </span> <span>will solve my problem but as you explained it is used for other cases.</span></div><div><span>please see that in </span><span style="font-weight: bold;"> ngx_http_send_special_response</span> when this flag set to 1 the Header is set with this fields but no body in response (I think this is not a good result)</div><div><br></div><div>if adding in the beginning of the function (<span style="font-weight: bold;">ngx_http_send_special_response) </span>the following code it solves the problem:<br></div><div>  if (r->header_only == 1)<br> 
 {<br>       ngx_http_clear_accept_ranges(r);<br>       ngx_http_clear_last_modified(r);<br><br>        rc = ngx_http_send_header(r);<br><br>        return rc;<br>   }</div><div><br></div><div><span>Is there any other way I can avoid content length and content-type in 302 response</span></div><div><span>Thanks</span></div><div><span>Hagai<br></span></div><div><span style="font-weight: bold;"><br></span></div><div><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Maxim
 Dounin <mdounin@mdounin.ru><br> <b><span style="font-weight: bold;">To:</span></b> nginx@nginx.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Monday, April 16, 2012 3:38 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: ngx_http_send_special_response<br> </font> </div> <br>
Hello!<br><br>On Mon, Apr 16, 2012 at 04:29:18AM -0700, hagai avrahami wrote:<br><br>> WOW thanks for the quick and elaborate response<br>> <br>> So what is the right way to send response with status code 302 on GET request but<br>> with content length 0 and no body (I want to redirect the request to other Server)<br><br>Easiest solution is to just write<br><br>    return 302 $where;<br><br>in config. :)<br><br>From the code point of view (assuming content handler context), <br>something like this should work:<br><br>    ngx_table_elt_t  *h;<br><br>    ngx_http_clear_location(r);<br><br>    h = ngx_list_push(&r->headers_out.headers);<br>    if (h == NULL) {<br>        return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>    }<br><br>    h->hash = 1;<br>    ngx_str_set(&h->key, "Location");<br><br>    h->value.data =
 ...<br>    h->value.len = ...<br><br>    r->headers_out.location = h;<br><br>    return NGX_HTTP_MOVED_TEMPORARILY;<br><br>Maxim Dounin<br><br><br>> <br>> Thanks <br>> <br>> Hagai<br>> <br>> <br>> <br>> <br>> >________________________________<br>> > From: Maxim Dounin <<a ymailto="mailto:mdounin@mdounin.ru" href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>><br>> >To: <a ymailto="mailto:nginx@nginx.org" href="mailto:nginx@nginx.org">nginx@nginx.org</a> <br>> >Sent: Monday, April 16, 2012 12:37 PM<br>> >Subject: Re: ngx_http_send_special_response<br>> > <br>> >Hello!<br>> ><br>> >On Mon, Apr 16, 2012 at 01:53:39AM -0700, hagai avrahami wrote:<br>> ><br>> >> <br>> >> <br>> >> Hi<br>> >> <br>> >> I am appreciate any help I can get on the following issues.<br>> >> <br>>
 >> I am writing my own module.<br>> >> <br>> >> 1. I can see in function ngx_http_send_special_response<br>> >>     that it calculates the content length of the error page even if the request signed as header only (r->header_only = 1)<br>> >>     and set the content length header with value, after sending the header it does not send the body ( because  r->header_only = 1)<br>> >>     so the response arrive with content length different than 0 but without body <br>> >> <br>> >>     Is it a BUG?<br>> ><br>> >No.  The r->header_only flag should is set when body isn't <br>> >expected per protocol (HEAD requests, 304 responses).  Having <br>> >Content-Length present in such responses is ok.<br>> ><br>> >> 2.In the module I am trying to redirect the request with status
 code 302 (NGX_HTTP_MOVED_TEMPORARILY)<br>> >>    Trying to user->headers_out.location for the Alternate URL failed, I looked in the code and saw the Location must start with "/" - why?<br>> ><br>> >You have to set it correctly, i.e. add to r->headers_out.headers <br>> >and link to r->headers_out.location.  If it starts with "/" it <br>> >works even if set incorrectly due to adding of a server_name, <br>> >that's probably what confused you.<br>> ><br>> >>    In the end I add it to r->headers_out.headers<br>> >>    using header = ngx_list_push(&r->headers_out.headers);<br>> >>    Is it the write way to do it?<br>> >> <br>> >> 3. Can you explain please the different between<br>> >>     a. r->headers_out.content_length_n<br>> >>     b.
 r->headers_out.content_length<br>> ><br>> >The content_length_n is a numeric length, this what you normaly <br>> >should set when generating response in nginx.  The content_length <br>> >is a pointer to a headers array element, it might be present if <br>> >there is string representation of a Content-Length header <br>> >available for some reason (e.g. from a backend).<br>> ><br>> >> 4. Can you explain the usage of the hash field in ngx_table_elt_t<br>> ><br>> >Normally the hash field is used for fast lookups in hash <br>> >structures.  In case of r->headers_out it's usually just set to 1 <br>> >indicate the header is valid (or reset to 0 to indicate the <br>> >header should not be sent as it was superseeded by some other <br>> >header).<br>> ><br>> >Maxim Dounin<br>> ><br>>
 >_______________________________________________<br>> >nginx mailing list<br>> ><a ymailto="mailto:nginx@nginx.org" href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>> >http://mailman.nginx.org/mailman/listinfo/nginx<br>> ><br>> ><br><br>> _______________________________________________<br>> nginx mailing list<br>> <a ymailto="mailto:nginx@nginx.org" href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>> <a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br><br>_______________________________________________<br>nginx mailing list<br><a ymailto="mailto:nginx@nginx.org" href="mailto:nginx@nginx.org">nginx@nginx.org</a><br><a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br><br> </div> </div> </blockquote></div>   </div></body></html>