# Remove Http header response

**URL:** <https://discuss.rubyonrails.org/t/remove-http-header-response/69159>\
**Category:** rubyonrails-talk\
**Created:** [June 18, 2014, 5:38am UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159 "2014-06-18T05:38:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 18, 2014, 5:38am UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/1 "2014-06-18T05:38:54Z")

</div>

Hi

I am working on a application which requires to make an api call to the rails application and it to return XML without any http header info.

its currently returning:

HTTP/1.1 200 OK Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Type: application/xml; charset= X-Ua-Compatible: IE=Edge X-Request-Id: c5602cd7eb23ca8137bef8bb1f0a4f8a X-Runtime: 0.027900 Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-11-22) Content-Length: 529 Connection: Keep-Alive Set-Cookie: \_session\_id=a8039d615674feec206e6c55a7a7afc8; path=/; HttpOnly

\<?xml version="1.0" encoding="UTF-8"?\> \<cXML\> &nbsp;&nbsp;\<Response\> &nbsp;&nbsp;&nbsp;&nbsp;\<Status code="200" text="OK"/\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<StartPage\> &nbsp;&nbsp;&nbsp;&nbsp;\<URL\>[http://localhost:3000/foobar/BAh7DDoNYmFza2V0aWRJIiYxL1Y3Ti9ITS0xODg3LzIwMTQtMDYtMThUMTU6NTY6wNjcwNzkwNzMwNzgwODMwMzIGOwZUOhFzZW5kZXJzZWNyZXQw--389c54274d1cfae03e0cd943a3dcbbfb149769b9&lt;/URL&gt](http://localhost:3000/foobar/BAh7DDoNYmFza2V0aWRJIiYxL1Y3Ti9ITS0xODg3LzIwMTQtMDYtMThUMTU6NTY6wNjcwNzkwNzMwNzgwODMwMzIGOwZUOhFzZW5kZXJzZWNyZXQw--389c54274d1cfae03e0cd943a3dcbbfb149769b9&lt;/URL&gt); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</StartPage\> &nbsp;&nbsp;\</Response\> \</cXML\>

Can anyone help to remove http headers from the controller?

HTTP/1.1 200 OK Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Type: application/xml; charset= X-Ua-Compatible: IE=Edge X-Request-Id: c5602cd7eb23ca8137bef8bb1f0a4f8a X-Runtime: 0.027900 Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-11-22) Content-Length: 529 Connection: Keep-Alive Set-Cookie: \_session\_id=a8039d615674feec206e6c55a7a7afc8; path=/; HttpOnly

Thanks in advance.

T

---

<div class="post-metadata">

**Author:** ![Jason\_FB](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/jason_fb/32/826_2.png) [@Jason\_FB](https://discuss.rubyonrails.org/u/Jason_FB)\
**Post date:** [June 18, 2014, 3:06pm UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/2 "2014-06-18T15:06:37Z")

</div>

For and XML response the header should be Content-type: text/xml

Generally all you need to do is pass format to the render block, or use respond\_with. Alternatively, you should be able to pass content\_type as a parameter to the render block.

But perhaps you meant you want to remove _all the headers_ from the response? This is kind of a nonsense request, since HTTP servers _by definition_ uses header to talk to one another.

That’s basically like asking to have a phone call with someone but not have the phone company use satellites or copper wires during the conversion.

What client-side application could you possibly be using to accept responses without any HTTP headers at all ?

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 24, 2014, 4:30pm UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/3 "2014-06-24T16:30:39Z")

</div>

You may think it is nonsense, W3 think otherwise. Perhaps you should inform them of their nonsense?

[http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4](http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4)

"message consist of a start-line, \*zero\* or more header fields"

---

<div class="post-metadata">

**Author:** ![Colin\_Law](https://avatars.discourse-cdn.com/v4/letter/c/b9e5f3/32.png) [@Colin\_Law](https://discuss.rubyonrails.org/u/Colin_Law)\
**Post date:** [June 24, 2014, 6:14pm UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/4 "2014-06-24T18:14:23Z")

</div>

Since it goes on to say (in 4.3) "The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request's message-headers" does that not imply that if there is are no headers then there can be no body either? I think the OP was looking for a body with no headers. Not to be confused with a headless body which would be quite different.

Colin

---

<div class="post-metadata">

**Author:** ![Norbert\_Melzer](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Norbert\_Melzer](https://discuss.rubyonrails.org/u/Norbert_Melzer)\
**Post date:** [June 24, 2014, 7:55pm UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/5 "2014-06-24T19:55:33Z")

</div>

He gets that snippet from another server, the opening does not want to create a body without headers, he wants to extract the actual body out of a full HTTP-response he got from external services.

So easiest way would be to drop everything before the first (and including it) newline, the remainder is the body, as described in the HTTP-RFC…

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 24, 2014, 8:44pm UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/6 "2014-06-24T20:44:27Z")

</div>

Norbert Melzer wrote in post #1150632:

> He gets that snippet from another server, the opening does not want to create a body without headers, he wants to extract the actual body out of a full HTTP-response he got from external services.
> 
> So easiest way would be to drop everything before the first (and including it) newline, the remainder is the body, as described in the HTTP-RFC...

Hi Norbert

My client only wish to receive the http body from me (rails application with nginx) and he is unable to extract from a full http response. Therefore any advise to just sent down only the response body is still very much appreciated.

T

Ps I also want to thank all have responded so far.

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 25, 2014, 8:38am UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/7 "2014-06-25T08:38:11Z")

</div>

Colin, Yes, it does say that, however, the "or" is important as it also says that the transfer encoding may be removed. The OP wants to send a response without any headers. This is within the rfc and so should be doable, regardless of how retarded it seems to be🙂

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 25, 2014, 8:42am UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/8 "2014-06-25T08:42:30Z")

</div>

Here's the syntax of the response:

[http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6](http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6)

---

<div class="post-metadata">

**Author:** ![Colin\_Law](https://avatars.discourse-cdn.com/v4/letter/c/b9e5f3/32.png) [@Colin\_Law](https://discuss.rubyonrails.org/u/Colin_Law)\
**Post date:** [June 25, 2014, 9:15pm UTC](https://discuss.rubyonrails.org/t/remove-http-header-response/69159/9 "2014-06-25T21:15:38Z")

</div>

> Colin, Yes, it does say that, however, the "or" is important as it also says that the transfer encoding may be removed.

Don't follow you there, where does it say the transfer encoding may be removed?

Colin
