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 CHANGED
@@ -14,7 +14,7 @@ require 'typhoeus/request'
14
14
  require 'typhoeus/hydra'
15
15
 
16
16
  module Typhoeus
17
- VERSION = "0.1.18"
17
+ VERSION = "0.1.19"
18
18
 
19
19
  def self.easy_object_pool
20
20
  @easy_objects ||= []
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix