# Content-Length header with HEAD response

**URL:** <https://www.ruby-forum.com/t/content-length-header-with-head-response/235071>\
**Category:** NGINX\
**Created:** [May 29, 2013, 1:50pm UTC](https://www.ruby-forum.com/t/content-length-header-with-head-response/235071 "2013-05-29T13:50:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [May 29, 2013, 1:50pm UTC](https://www.ruby-forum.com/t/content-length-header-with-head-response/235071/1 "2013-05-29T13:50:29Z")

</div>

Hi

I am trying to configure Nginx to deny HTTP HEAD requests

1. By adding the following to configuration file

if ($request\_method !~ ^(GET)$) {  
return 405;  
}

1. Explicitly in the module

if (!(r-\>method & (NGX\_HTTP\_GET))) {  
return NGX\_HTTP\_NOT\_ALLOWED;  
}

Nginx returns 405 status code but the response content length is not 0  
it’s counting the error page text but when coming to send the response  
it  
ignores the body because it is HEAD request

HTTP/1.1 405 Not Allowed  
Server: nginx  
Date: Wed, 29 May 2013 11:35:02 GMT  
Content-Type: text/html  
Content-Length: 161  
Connection: keep-alive

\ ***No-Body**

Please Advise  
Thanks  
Hagai A.

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [May 29, 2013, 2:11pm UTC](https://www.ruby-forum.com/t/content-length-header-with-head-response/235071/2 "2013-05-29T14:11:31Z")

</div>

Hello!

On Wed, May 29, 2013 at 02:49:46PM +0300, Hagai A. wrote:

> 1. Explicitly in the module  
> Server: nginx  
> Date: Wed, 29 May 2013 11:35:02 GMT  
> Content-Type: text/html  
> Content-Length: 161  
> Connection: keep-alive
> 
> \ ***No-Body**

And the question is? The behaviour you observe is correct as per  
HTTP protocol.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [May 29, 2013, 2:53pm UTC](https://www.ruby-forum.com/t/content-length-header-with-head-response/235071/3 "2013-05-29T14:53:36Z")

</div>

Hi  
I thought HEAD should behave as GET only in case of success  
after reading the RFC I understand it’s should be the same on any  
response  
Thanks

On Wed, May 29, 2013 at 3:10 PM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > if ($request\_method !~ ^(GET)$) {  
> > it’s counting the error page text but when coming to send the response it
> 
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

_Hagai A._  
Qwilt | Work: +972-72-2221644| Mobile: +972-54-4895656 |  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
