httpsimple 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/httpsimple.rb +10 -4
  2. metadata +1 -1
data/lib/httpsimple.rb CHANGED
@@ -2,6 +2,7 @@ require 'net/http'
2
2
  require 'uri'
3
3
 
4
4
  module HttpSimple
5
+ VERSION='1.0.1'
5
6
  def self.get(url, data=nil, &block)
6
7
  request(url, :get, data, &block)
7
8
  end
@@ -30,13 +31,14 @@ module HttpSimple
30
31
 
31
32
  class Http
32
33
  attr_accessor :headers, :max_redirects,
33
- :strict_ssl, :timeout, :handlers
34
+ :strict_ssl, :timeout, :handlers, :follow_redirects
34
35
  attr_reader :url
35
36
 
36
37
  def initialize
37
38
 
38
39
  @headers = {}
39
- @max_redirects = 3
40
+ @max_redirects = 3
41
+ @follow_redirects = true
40
42
  @strict_ssl = true
41
43
  @timeout = 90
42
44
  # Response handlers
@@ -109,12 +111,16 @@ module HttpSimple
109
111
  when Net::HTTPSuccess
110
112
  return response
111
113
  when Net::HTTPRedirection
114
+ return response unless @follow_redirects
112
115
  raise HTTPMaxRedirectError.new(@max_redirects) if limit == 0
113
116
  block = lambda { |url, req| fetch(url, req, limit - 1) }
117
+ new_uri = URI(response['location'])
118
+ # Handle relative redirects ie /foo
119
+ new_uri = uri + new_uri unless new_uri.is_a? URI::HTTP
114
120
  if request.is_a? Net::HTTP::Get
115
- get(response['location'], &block)
121
+ get(new_uri, &block)
116
122
  elsif request.is_a? Net::HTTP::Post
117
- post(response['location'], &block)
123
+ post(new_uri, &block)
118
124
  end
119
125
  when Net::HTTPResponse
120
126
  response.error!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpsimple
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: