Permalink
Browse files

Added example of response headers.

  • Loading branch information...
1 parent a817daa commit dbe7dda7c4b53a501ab617d5a33a173e3f07b570 @augustl committed Jun 23, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1 headers.rb
View
@@ -8,4 +8,20 @@
request["User-Agent"] = "My Ruby Script"
request["Accept"] = "*/*"
-response = http.request(request)
+response = http.request(request)
+
+# Get specific header
+response["content-type"]
+# => "text/html; charset=UTF-8"
+
+# Iterate all response headers.
+response.each_header do |key, value|
+ p "#{key} => #{value}"
+end
+# => "location => http://www.google.com/"
+# => "content-type => text/html; charset=UTF-8"
+# ...
+
+# Alternatively, reach into private APIs.
+p response.instance_variable_get("@header")
+# => {"location"=>["http://www.google.com/"], "content-type"=>["text/html; charset=UTF-8"], ...}

0 comments on commit dbe7dda

Please sign in to comment.