http-request 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/http-request.rb +18 -13
  3. metadata +19 -40
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
data/lib/http-request.rb CHANGED
@@ -33,11 +33,11 @@
33
33
  require 'net/http'
34
34
 
35
35
  class HttpRequest
36
- VERSION = '1.0.3'
37
-
36
+ VERSION = '1.0.4'
37
+
38
38
  class HTTPError < StandardError; end
39
39
  class UnexpectedError < StandardError; end
40
-
40
+
41
41
  class UnreachableError < HTTPError; end
42
42
  class ConnectionResetError < HTTPError; end
43
43
  class TimeoutError < HTTPError; end
@@ -81,39 +81,44 @@ class HttpRequest
81
81
  redirect_limit = options[:redirect_limit] || 5
82
82
  output_file = options[:output_file]
83
83
  content_max = options[:content_max]
84
-
84
+
85
85
  # Check if we're in a redirecting loop
86
86
  if redirect_limit == 0
87
87
  raise RedirectError, "HTTP redirect too deep: #{uri.to_s}"
88
88
  end
89
-
89
+
90
90
  # Prepare the request
91
91
  req_path = uri.path
92
92
  req_path += "?#{uri.query}" if !uri.query.nil?
93
-
93
+
94
94
  req_klass = (type == :head ? Net::HTTP::Head : Net::HTTP::Get)
95
95
  req = req_klass.new(req_path, { 'User-Agent' => user_agent })
96
96
 
97
+ # Basic authentication
98
+ if uri.user && uri.password
99
+ req.basic_auth uri.user, uri.password
100
+ end
101
+
97
102
  # HTTP request block
98
103
  @retries = 3
99
104
  begin
100
105
  http = Net::HTTP.new(uri.host, uri.port)
101
-
106
+
102
107
  http.open_timeout = timeout
103
108
  http.read_timeout = timeout
104
-
109
+
105
110
  http.start do |http|
106
111
  http.request(req) do |response|
107
112
  # Save the header
108
113
  self.header = response.header
109
114
  self.body = nil
110
-
115
+
111
116
  # Restrict downloading of content
112
117
  download_content = true
113
118
  if !content_max.nil? && header['content-length'].to_i > content_max
114
119
  download_content = false
115
120
  end
116
-
121
+
117
122
  # Get the body
118
123
  if download_content
119
124
  if output_file
@@ -124,7 +129,7 @@ class HttpRequest
124
129
  self.body = response.read_body
125
130
  end
126
131
  end
127
-
132
+
128
133
  # Handle URL Redirection
129
134
  if response.kind_of?(Net::HTTPRedirection) && !header['location'].nil?
130
135
  update_uri_location(header['location'])
@@ -156,7 +161,7 @@ class HttpRequest
156
161
  http.finish rescue nil
157
162
  http = nil
158
163
  end
159
-
164
+
160
165
  return self
161
166
  end
162
167
 
@@ -180,7 +185,7 @@ class HttpRequest
180
185
 
181
186
  def update_uri_location(location)
182
187
  if header['location'].to_s[0].to_s.chr == '/'
183
- url = "#{uri.scheme}://#{uri.host}"
188
+ url = "#{uri.scheme}://#{uri.host}"
184
189
  url += ":#{uri.port}" if uri.port != 80 && uri.port != 443
185
190
  url += location
186
191
  else
metadata CHANGED
@@ -1,69 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: http-request
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 3
9
- version: 1.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Peter Kieltyka
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-27 00:00:00 -05:00
18
- default_executable:
12
+ date: 2012-02-21 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Simple HTTP client built with Net/HTTP
22
- email:
15
+ email:
23
16
  - peter.kieltyka@nulayer.com
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - README
32
22
  - VERSION
33
23
  - lib/http-request.rb
34
- has_rdoc: true
35
24
  homepage: http://nulayer.com
36
25
  licenses: []
37
-
38
26
  post_install_message:
39
27
  rdoc_options: []
40
-
41
- require_paths:
28
+ require_paths:
42
29
  - lib
43
- required_ruby_version: !ruby/object:Gem::Requirement
30
+ required_ruby_version: !ruby/object:Gem::Requirement
44
31
  none: false
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- segments:
49
- - 0
50
- version: "0"
51
- required_rubygems_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
37
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- segments:
57
- - 1
58
- - 3
59
- - 6
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
60
41
  version: 1.3.6
61
42
  requirements: []
62
-
63
43
  rubyforge_project:
64
- rubygems_version: 1.3.7
44
+ rubygems_version: 1.8.17
65
45
  signing_key:
66
46
  specification_version: 3
67
47
  summary: Simple HTTP client built with Net/HTTP
68
48
  test_files: []
69
-