The calendar is gone.
Click here to view posts


Rails http head
As it turns out rails implements HTTP head calls for you. A fellow programmer was creating rails functional tests and using rcow noticed that we did not write test for the head command. He then found out that the functional test in rails when creating the mock response object includes the body like a normal get call. We reread the spec for http head one more time just in case we both thought incorrectly. So, I fired up the test using code komodo's ruby debugger. for the next 2 hours we stepped in the tes setup code and the rails frame work. We stepped in a lot of code until we hit the trunk/vendor/rails/actionpack/lib/action_controller/request.rb:line 16

# Returns the HTTP request method as a lowercase symbol (:get, for example). Note, HEAD is returned as :get
# since the two are supposedly to be functionaly equivilent for all purposes except that HEAD won't return a response
# body (which Rails also takes care of elsewhere).
def method
 @request_method ||= (!parameters[:_ethod].blank? && @env['REQUEST_METHOD'] == 'POST') ?
        parameters[:_method].to_s.downcase.to_sym :
 @env['REQUEST_METHOD'].downcase.to_sym
      
 @request_method == :head ? :get : @request_method
end


I did kept stepping in but I never found the code that takes care of the head body problem. We tested the head call using curl and it works, but the test returns the body like a normal get call.

So it must be code that is not ran for the testing frame work. Ihope to find the other code for the head call but I am having a hard time learning how to debug live rails apps.

Read up on your http head request here it is useful for caching. We all know what caching can lead to.

Just something i thought was cool.

Httpresponsecodes
When developing code that uses web services I often code for the error case. What if I get back a 404 or 500? This is what I should do. I often have a hard time testing this. Some times the service provides a way to trigger errors. Those calls often are all about the payload.

I have started a new website httpresponsecodes.com that will take a code like 200 and give you back a 200 response. You can also set the body. For example http://www.httpresponsecodes.com/200?response_body=cow

Leaving of the response_body will return some details about the code. I dont have all the details on all the codes yet but 200 works fine. Its also one of the few that the browser renders fine.

Examples:

200 with body

200 with details of 200

500 with json http://www.httpresponsecodes.com/500?response_body={"zip":20}