Last active
August 29, 2015 13:56
-
-
Save raorao/8966135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#HTTParty isn't broken! it deals with 304 errors as per RFC 2616, | |
#returning a response with headers but no body. | |
require 'httparty' | |
response = HTTParty.get("https://api.github.com/users/octocat", { | |
:headers => {"User-Agent" => "HTTParty"}, | |
}) | |
etag = response.headers["etag"] | |
response = HTTParty.get("https://api.github.com/users/octocat", { | |
:headers => { "If-None-Match" => etag, "User-Agent" => "HTTParty"} | |
}) | |
puts response | |
#nil | |
puts response.headers["date"] | |
# Wed, 12 Feb 2014 22:45:32 GMT | |
puts response.headers["etag"] | |
# "e0b2dfe317b38e9e8e2bb2a22fecb08f" | |
puts response.headers.inspect | |
# {"server"=>["GitHub.com"], | |
# "date"=>["Wed, 12 Feb 2014 22:45:32 GMT"], | |
# "connection"=>["close"], | |
# "status"=>["304 Not Modified"], | |
# "x-ratelimit-limit"=>["60"], | |
# "x-ratelimit-remaining"=>["35"], | |
# "x-ratelimit-reset"=>["1392247594"], | |
# "cache-control"=>["public, max-age=60, s-maxage=60"], | |
# "last-modified"=>["Wed, 12 Feb 2014 16:24:12 GMT"], | |
# "etag"=>["\"e0b2dfe317b38e9e8e2bb2a22fecb08f\""], | |
# "x-content-type-options"=>["nosniff"], | |
# "access-control-allow-credentials"=>["true"], | |
# "access-control-expose-headers"=>["ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"], | |
# "access-control-allow-origin"=>["*"], | |
# "x-github-request-id"=>["{{SOME HEX}}"], | |
# "vary"=>["Accept-Encoding"] | |
# } |
I mean its a little strange that a body-less response would print nothing to the screen, but it does match the httparty gem specifications.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh blast! I was thinking maybe I was an idiot and the response object might respond to headers even though there's no body.
(Because response is just an alias for response.body.)