typhoeus 0.1.11 → 0.1.12

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.11"
17
+ VERSION = "0.1.12"
18
18
 
19
19
  def self.easy_object_pool
20
20
  @easy_objects ||= []
@@ -122,6 +122,7 @@ module Typhoeus
122
122
  easy.headers = request.headers if request.headers
123
123
  easy.request_body = request.body if request.body
124
124
  easy.timeout = request.timeout if request.timeout
125
+ easy.follow_location = request.follow_location if request.follow_location
125
126
  easy.on_success do |easy|
126
127
  queue_next
127
128
  handle_request(request, response_from_easy(easy, request))
@@ -1,6 +1,6 @@
1
1
  module Typhoeus
2
2
  class Request
3
- attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout
3
+ attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location
4
4
  attr_reader :url
5
5
 
6
6
  def initialize(url, options = {})
@@ -11,6 +11,7 @@ module Typhoeus
11
11
  @headers = options[:headers] || {}
12
12
  @user_agent = options[:user_agent] || Typhoeus::USER_AGENT
13
13
  @cache_timeout = options[:cache_timeout]
14
+ @follow_location = options[:follow_location]
14
15
  if @method == :post
15
16
  @url = url
16
17
  else
@@ -112,4 +113,4 @@ module Typhoeus
112
113
  run(url, params.merge(:method => :delete))
113
114
  end
114
115
  end
115
- end
116
+ end
data/spec/servers/app.rb CHANGED
@@ -17,6 +17,10 @@ get '/fail_forever' do
17
17
  error 500, "oh noes!"
18
18
  end
19
19
 
20
+ get '/redirect' do
21
+ redirect '/'
22
+ end
23
+
20
24
  get '/**' do
21
25
  sleep params["delay"].to_i if params.has_key?("delay")
22
26
  request.env.merge!(:body => request.body.read).to_json
@@ -2,8 +2,34 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Typhoeus::Easy do
4
4
  describe "options" do
5
- it "should allow for following redirects"
6
- it "should allow you to set the user agent"
5
+ it "should not follow redirects if not instructed to" do
6
+ e = Typhoeus::Easy.new
7
+ e.url = "http://localhost:3001/redirect"
8
+ e.method = :get
9
+ e.perform
10
+ e.response_code.should == 302
11
+ end
12
+
13
+ it "should allow for following redirects" do
14
+ e = Typhoeus::Easy.new
15
+ e.url = "http://localhost:3001/redirect"
16
+ e.method = :get
17
+ e.follow_location = true
18
+ e.perform
19
+ e.response_code.should == 200
20
+ JSON.parse(e.response_body)["REQUEST_METHOD"].should == "GET"
21
+ end
22
+
23
+ it "should allow you to set the user agent" do
24
+ easy = Typhoeus::Easy.new
25
+ easy.url = "http://localhost:3002"
26
+ easy.method = :get
27
+ easy.user_agent = "myapp"
28
+ easy.perform
29
+ easy.response_code.should == 200
30
+ JSON.parse(easy.response_body)["HTTP_USER_AGENT"].should == "myapp"
31
+ end
32
+
7
33
  it "should provide a timeout in milliseconds" do
8
34
  e = Typhoeus::Easy.new
9
35
  e.url = "http://localhost:3001"
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.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix