0

If someone POSTs to my Rails application with HTTP version 1.0 like this:

POST /update HTTP/1.0

How do I send an HTTP version 1.0 response like this:

HTTP/1.0 200 OK

I'm using Ruby on Rails 3. Rails responses always seem to be HTTP version 1.1, but if the client sends a request with HTTP version 1.0 I want to respond with HTTP version 1.0.

1 Answer 1

1

If you want your controller to build Header-only responses, you can use the head method. Example:

head :bad_request

Would produce the following header:

HTTP/1.1 400 Bad Request
Connection: close
Date: Sun, 24 Jan 2010 12:15:53 GMT
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
X-Runtime: 0.013483
Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
Cache-Control: no-cache

More information

Sign up to request clarification or add additional context in comments.

5 Comments

This doesn't help me to change the HTTP version of the response.
Why would you want to change the HTTP version? I guess you just want to send another status code, which is exactly what head does. If this is not what you are looking for, make your question more clear.
I want the HTTP version of the response to be the same as that of the request.
I see. Never thought about that. Don't know if such thing is built right into Rails.
if you can't find a way in rails (which would be surprising if there is a use for doing so) you could consider rack middleware to modify the response once it leaves rails

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.