typhoeus 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/typhoeus.rb +1 -1
- data/lib/typhoeus/response.rb +12 -0
- data/spec/typhoeus/response_spec.rb +9 -0
- metadata +1 -1
data/lib/typhoeus.rb
CHANGED
data/lib/typhoeus/response.rb
CHANGED
@@ -15,5 +15,17 @@ module Typhoeus
|
|
15
15
|
@start_time = params[:start_time]
|
16
16
|
@request = params[:request]
|
17
17
|
end
|
18
|
+
|
19
|
+
def headers_hash
|
20
|
+
headers.split("\n").map {|o| o.strip}.inject({}) do |hash, o|
|
21
|
+
if o.empty?
|
22
|
+
hash
|
23
|
+
else
|
24
|
+
o = o.split(":")
|
25
|
+
hash[o.first.strip] = o.last ? o.last.strip : nil
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
18
30
|
end
|
19
31
|
end
|
@@ -33,4 +33,13 @@ describe Typhoeus::Response do
|
|
33
33
|
response.request.should == "whatever"
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
describe "headers" do
|
38
|
+
it "can parse the headers into a hash" do
|
39
|
+
response = Typhoeus::Response.new(:headers => "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nConnection: close\r\nStatus: 200\r\nX-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.9\r\nX-Cache: miss\r\nX-Runtime: 184\r\nETag: e001d08d9354ab7bc7c27a00163a3afa\r\nCache-Control: private, max-age=0, must-revalidate\r\nContent-Length: 4725\r\nSet-Cookie: _some_session=BAh7CDoGciIAOg9zZXNzaW9uX2lkIiU1OTQ2OTcwMjljMWM5ZTQwODU1NjQwYTViMmQxMTkxMjoGcyIKL2NhcnQ%3D--b4c4663932243090c961bb93d4ad5e4327064730; path=/; HttpOnly\r\nServer: nginx/0.6.37 + Phusion Passenger 2.2.4 (mod_rails/mod_rack)\r\nP3P: CP=\"NOI DSP COR NID ADMa OPTa OUR NOR\"\r\n\r\n")
|
40
|
+
response.headers_hash["Status"].should == "200"
|
41
|
+
response.headers_hash["Set-Cookie"].should == "_some_session=BAh7CDoGciIAOg9zZXNzaW9uX2lkIiU1OTQ2OTcwMjljMWM5ZTQwODU1NjQwYTViMmQxMTkxMjoGcyIKL2NhcnQ%3D--b4c4663932243090c961bb93d4ad5e4327064730; path=/; HttpOnly"
|
42
|
+
response.headers_hash["Content-Type"].should == "text/html; charset=utf-8"
|
43
|
+
end
|
44
|
+
end
|
36
45
|
end
|