user3751048
user3751048

Reputation: 3

Remove Http header response

I am working on a project which requires a client to make an api call to my 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)
Date: Wed, 18 Jun 2014 05:27:48 GMT
Content-Length: 529
Connection: Keep-Alive
Set-Cookie: _session_id=a8039d615674feec206e6c55a7a7afc8; path=/;
HttpOnly

<?xml version="1.0" encoding="UTF-8"?>
<cXML>
  <Response>
    <Status code="200" text="OK"/>
      <StartPage>
    <URL>http://localhost:3000/foobar/BAh7DDoNYmFza2V0aWRJI...
      </StartPage>
  </Response>
</cXML>

Can anyone help to remove all the http headers within the controller or any config? which is below section.

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)
Date: Wed, 18 Jun 2014 05:27:48 GMT
Content-Length: 529
Connection: Keep-Alive
Set-Cookie: _session_id=a8039d615674feec206e6c55a7a7afc8; path=/;
HttpOnly

I am using nginx at the moment.

I have some says that this is kind of a nonsense request, since HTTP servers by definition uses header to talk to one another. But I have also been informed that W3 think otherwise.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4

I have also googled around for hours attempting other solutions changing my rails controller without any success. Is the last resort possibly changing config in Nginx and wouldn't that effect the whole rails application and not just the api calls or is there a way to single out one call?

Thanks in advance.

T

Upvotes: 0

Views: 1469

Answers (1)

James Mason
James Mason

Reputation: 4296

This is a nonsense request, yeah. You can use the HttpHeadersMore module to remove most of the response headers. Something like this should do it:

location /your/api/path {
  more_clear_headers '*';
}

However, you can't remove the Connections header without patching nginx. And even if you could, you can't remove the first line of the response ("HTTP/1.1 200 OK", in this case). Without that line, it isn't an HTTP response. You're going to have a hard time convincing an HTTP server to send non-HTTP responses.

To get what you're describing, I think you'll need a custom server that communicates over bare TCP sockets. This tutorial might help you out. Or maybe you could implement that part of your app in node.js (or another tool)?

Upvotes: 1

Related Questions