typhoeus 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 79bd3451f6ec67ea973d9dc62dc4645c21e2eba1
4
- data.tar.gz: 762e3c44e97fc0f2241d5cbf9d2a9ff2caa8a53a
2
+ SHA256:
3
+ metadata.gz: b1a6b0485477d252e7eb99852bec27994e9c23aa54e7d376cd24bc07d3639d5c
4
+ data.tar.gz: d2dbaf34e81e7a906dbf254d0d1aa1d6028c10a08605b6dc6261c282bfc39abd
5
5
  SHA512:
6
- metadata.gz: e0a7c0b640b05b4527a4a9a7b3ee7db526fc25e31e001b7287f2423fecebbf6d673adb5c17b7cda32c1206872a3a27d82825b9ee74974607f691e9ee573fb39a
7
- data.tar.gz: 444398bc7499402359de7a5534c265bf91c39346903c1b82c4767b1b7f9eb9c72741a979986b905e388301055e6816baa6ef999f9f35bed06a07a4bec37d7b99
6
+ metadata.gz: 711db47d856f75d5eb730e11161e02a6a6f6c6d9e966aeec3ace577d250d57a790c2d0d5ade86fda425bff6b5f6d5c77079107a3f41a2379d4bff9cd802ca712
7
+ data.tar.gz: 52cfa55fe418b64ed16e094a497d6fc72092b8d5745d81860aead9e35a6dba403fb2375674ca652ba6bb8e5acac29ed5ce03161c2c68dc0f1de9d44ad65ac277
@@ -0,0 +1,30 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ build:
5
+ env:
6
+ BUNDLE_GEMFILE: Gemfile
7
+ runs-on: ${{ matrix.os }}-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ os: [ubuntu, macos]
12
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', truffleruby]
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Install libcurl header
16
+ run: |
17
+ if ${{ matrix.os == 'macos' }}
18
+ then
19
+ brew install curl
20
+ else
21
+ sudo apt update && sudo apt install -y --no-install-recommends libcurl4-openssl-dev
22
+ fi
23
+ - name: Set up Ruby ${{ matrix.ruby-version }}
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby-version }}
27
+ bundler-cache: true
28
+ - name: Run tests
29
+ run: |
30
+ bundle exec rake
@@ -0,0 +1,33 @@
1
+ name: Experimental
2
+ on: [push, pull_request]
3
+ jobs:
4
+ build:
5
+ env:
6
+ BUNDLE_GEMFILE: Gemfile
7
+ runs-on: ${{ matrix.os }}-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ os: [ubuntu, macos]
12
+ ruby-version:
13
+ - ruby-head
14
+ - jruby-head
15
+ - truffleruby-head
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - name: Install libcurl header
19
+ run: |
20
+ if ${{ matrix.os == 'macos' }}
21
+ then
22
+ brew install curl
23
+ else
24
+ sudo apt update && sudo apt install -y --no-install-recommends libcurl4-openssl-dev
25
+ fi
26
+ - name: Set up Ruby ${{ matrix.ruby-version }}
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby-version }}
30
+ bundler-cache: true
31
+ - name: Run tests
32
+ run: |
33
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.4.0...master)
5
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.4.1...master)
6
+
7
+ ## 1.4.1
8
+
9
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.4.0...v1.4.1)
6
10
 
7
11
  ## 1.4.0
8
12
 
data/Gemfile CHANGED
@@ -15,10 +15,14 @@ group :development, :test do
15
15
  gem "sinatra", "~> 1.3"
16
16
 
17
17
  if Gem.ruby_version >= Gem::Version.new("1.9.0")
18
- gem "faraday", ">= 0.9"
18
+ gem "faraday", ">= 0.9", "< 2.0"
19
19
  gem "dalli", "~> 2.0"
20
20
  end
21
21
 
22
+ if Gem.ruby_version >= Gem::Version.new("3.0.0")
23
+ gem 'webrick'
24
+ end
25
+
22
26
  gem "redis", "~> 3.0"
23
27
 
24
28
  if RUBY_PLATFORM == "java"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Typhoeus [![Build Status](https://img.shields.io/travis/typhoeus/typhoeus/master.svg)](https://travis-ci.org/typhoeus/typhoeus) [![Code Climate](https://img.shields.io/codeclimate/maintainability/typhoeus/typhoeus.svg)](https://codeclimate.com/github/typhoeus/typhoeus) [![Gem Version](https://img.shields.io/gem/v/typhoeus.svg)](https://rubygems.org/gems/typhoeus)
1
+ # Typhoeus [![CI](https://github.com/typhoeus/typhoeus/actions/workflows/ci.yml/badge.svg)](https://github.com/typhoeus/typhoeus/actions/workflows/ci.yml) [![Experimental](https://github.com/typhoeus/typhoeus/actions/workflows/experimental.yml/badge.svg)](https://github.com/typhoeus/typhoeus/actions/workflows/experimental.yml) [![Code Climate](https://img.shields.io/codeclimate/maintainability/typhoeus/typhoeus.svg)](https://codeclimate.com/github/typhoeus/typhoeus) [![Gem Version](https://img.shields.io/gem/v/typhoeus.svg)](https://rubygems.org/gems/typhoeus)
2
2
 
3
3
  Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
4
4
 
@@ -19,11 +19,10 @@ hydra.run
19
19
  ```
20
20
 
21
21
  ## Installation
22
- Add the following line to your Gemfile:
22
+ Run:
23
23
  ```
24
- gem "typhoeus"
24
+ bundle add typhoeus
25
25
  ```
26
- Then run `bundle install`
27
26
 
28
27
  Or install it yourself as:
29
28
 
@@ -33,8 +32,7 @@ gem install typhoeus
33
32
 
34
33
  ## Project Tracking
35
34
 
36
- * [Documentation](http://rubydoc.info/github/typhoeus/typhoeus/frames/Typhoeus) (GitHub master)
37
- * [Mailing list](http://groups.google.com/group/typhoeus)
35
+ * [API Documentation](https://rubydoc.info/github/typhoeus/typhoeus/frames/Typhoeus) (GitHub master)
38
36
 
39
37
  ## Usage
40
38
 
@@ -350,6 +348,8 @@ Typhoeus.get("www.example.com").cached?
350
348
  For use with [Dalli](https://github.com/mperham/dalli):
351
349
 
352
350
  ```ruby
351
+ require "typhoeus/cache/dalli"
352
+
353
353
  dalli = Dalli::Client.new(...)
354
354
  Typhoeus::Config.cache = Typhoeus::Cache::Dalli.new(dalli)
355
355
  ```
@@ -357,12 +357,16 @@ Typhoeus::Config.cache = Typhoeus::Cache::Dalli.new(dalli)
357
357
  For use with Rails:
358
358
 
359
359
  ```ruby
360
+ require "typhoeus/cache/rails"
361
+
360
362
  Typhoeus::Config.cache = Typhoeus::Cache::Rails.new
361
363
  ```
362
364
 
363
365
  For use with [Redis](https://github.com/redis/redis-rb):
364
366
 
365
367
  ```ruby
368
+ require "typhoeus/cache/redis"
369
+
366
370
  redis = Redis.new(...)
367
371
  Typhoeus::Config.cache = Typhoeus::Cache::Redis.new(redis)
368
372
  ```
@@ -44,6 +44,22 @@ module Typhoeus
44
44
  # @see http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTVERBOSE
45
45
  attr_accessor :verbose
46
46
 
47
+ # Defines the default HTTP timeout for the entire request in seconds
48
+ # See README for more details about timeouts
49
+ #
50
+ # @return [ Integer, Float ]
51
+ #
52
+ # @see https://curl.haxx.se/libcurl/c/curl_easy_setopt#CURLOPTTIMEOUT
53
+ attr_accessor :timeout
54
+
55
+ # Defines the default HTTP timeout for the connection phase in seconds
56
+ # See README for more details about timeouts
57
+ #
58
+ # @return [ Integer, Float ]
59
+ #
60
+ # @see https://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCONNECTTIMEOUT
61
+ attr_accessor :connecttimeout
62
+
47
63
  # Defines whether requests are cached.
48
64
  #
49
65
  # @return [ Object ]
@@ -78,11 +78,17 @@ module Typhoeus
78
78
  # @return [ Ethon::Easy ] The easy.
79
79
  def get
80
80
  begin
81
+ read_callback_body = request.options.delete(:set_read_callback)
82
+
81
83
  easy.http_request(
82
84
  request.base_url.to_s,
83
85
  request.options.fetch(:method, :get),
84
86
  sanitize(request.options)
85
87
  )
88
+
89
+ # this needs to happen after http_request because
90
+ # ethon will set infilesize to zero if form.empty?
91
+ set_read_callback(read_callback_body) if !read_callback_body.nil?
86
92
  rescue Ethon::Errors::InvalidOption => e
87
93
  help = provide_help(e.message.match(/:\s(\w+)/)[1])
88
94
  raise $!, "#{$!}#{help}", $!.backtrace
@@ -169,6 +175,26 @@ module Typhoeus
169
175
  end
170
176
  end
171
177
 
178
+ # Sets up an easy upload with CURLOPT_READFUNCTION
179
+ # along with CURLOPT_INFILESIZE_LARGE and CURLOPT_UPLOAD
180
+ #
181
+ # @param [ String/File ] body The body read by the readfunction.
182
+ #
183
+ # @return [ Ethon::Easy ] The easy.
184
+ def set_read_callback(body)
185
+ easy.infilesize_large =
186
+ if body.respond_to?(:bytesize)
187
+ body.bytesize
188
+ elsif body.respond_to?(:size)
189
+ body.size
190
+ end
191
+
192
+ easy.upload = true
193
+ easy.set_read_callback(body)
194
+
195
+ easy
196
+ end
197
+
172
198
  def provide_help(option)
173
199
  if new_option = CHANGED_OPTIONS[option.to_sym]
174
200
  "\nPlease try #{new_option} instead of #{option}." if new_option
@@ -214,6 +214,8 @@ module Typhoeus
214
214
  options[:headers] = {'User-Agent' => default_user_agent}.merge(options[:headers] || {})
215
215
  options[:headers]['Expect'] ||= ''
216
216
  options[:verbose] = Typhoeus::Config.verbose if options[:verbose].nil? && !Typhoeus::Config.verbose.nil?
217
+ options[:timeout] = Typhoeus::Config.timeout if options[:timeout].nil? && !Typhoeus::Config.timeout.nil?
218
+ options[:connecttimeout] = Typhoeus::Config.connecttimeout if options[:connecttimeout].nil? && !Typhoeus::Config.connecttimeout.nil?
217
219
  options[:maxredirs] ||= 50
218
220
  options[:proxy] = Typhoeus::Config.proxy unless options.has_key?(:proxy) || Typhoeus::Config.proxy.nil?
219
221
  end
@@ -210,10 +210,67 @@ module Typhoeus
210
210
  options[:redirect_count]
211
211
  end
212
212
 
213
+ # Return the URL a redirect would take you to, had you enabled redirects.
214
+ #
215
+ # @example Get redirect_url.
216
+ # response.redirect_url
217
+ #
218
+ # @return [ String ] The redirect_url.
219
+ def redirect_url
220
+ options[:redirect_url]
221
+ end
222
+
213
223
  def request_size
214
224
  options[:request_size]
215
225
  end
216
226
 
227
+ # Return the bytes, the total amount of bytes that were uploaded
228
+ #
229
+ # @example Get size_upload.
230
+ # response.size_upload
231
+ #
232
+ # @return [ Float ] The size_upload.
233
+ def size_upload
234
+ options[:size_upload]
235
+ end
236
+
237
+
238
+ # Return the bytes, the total amount of bytes that were downloaded.
239
+ # The amount is only for the latest transfer and will be reset again
240
+ # for each new transfer. This counts actual payload data, what's
241
+ # also commonly called body. All meta and header data are excluded
242
+ # and will not be counted in this number.
243
+ #
244
+ # @example Get size_download
245
+ # response.size_download
246
+ #
247
+ # @return [ Float ] The size_download.
248
+ def size_download
249
+ options[:size_download]
250
+ end
251
+
252
+ # Return the bytes/second, the average upload speed that curl
253
+ # measured for the complete upload
254
+ #
255
+ # @example Get speed_upload.
256
+ # response.speed_upload
257
+ #
258
+ # @return [ Float ] The speed_upload.
259
+ def speed_upload
260
+ options[:speed_upload]
261
+ end
262
+
263
+ # Return the bytes/second, the average download speed that curl
264
+ # measured for the complete download
265
+ #
266
+ # @example Get speed_download.
267
+ # response.speed_download
268
+ #
269
+ # @return [ Float ] The speed_download.
270
+ def speed_download
271
+ options[:speed_download]
272
+ end
273
+
217
274
  def debug_info
218
275
  options[:debug_info]
219
276
  end
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '1.4.0'
4
+ VERSION = '1.4.1'
5
5
  end
@@ -2,7 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe Typhoeus::Request do
4
4
  let(:base_url) { "localhost:3001" }
5
- let(:options) { {:verbose => true, :headers => { 'User-Agent' => "Fubar", 'Expect' => "" }, :maxredirs => 50} }
5
+ let(:options) do
6
+ {
7
+ verbose: true,
8
+ headers: { "User-Agent" => "Fubar", "Expect" => "" },
9
+ maxredirs: 50
10
+ }
11
+ end
6
12
  let(:request) { Typhoeus::Request.new(base_url, options) }
7
13
 
8
14
  describe ".url" do
@@ -95,6 +101,24 @@ describe Typhoeus::Request do
95
101
  end
96
102
  end
97
103
 
104
+ context "when Config.timeout set" do
105
+ before { Typhoeus.configure { |config| config.timeout = 10 } }
106
+ after { Typhoeus.configure { |config| config.timeout = nil } }
107
+
108
+ it "respects configuration" do
109
+ expect(request.options[:timeout]).to eq(10)
110
+ end
111
+ end
112
+
113
+ context "when Config.connecttimeout set" do
114
+ before { Typhoeus.configure { |config| config.connecttimeout = 10 } }
115
+ after { Typhoeus.configure { |config| config.connecttimeout = nil } }
116
+
117
+ it "respects configuration" do
118
+ expect(request.options[:connecttimeout]).to eq(10)
119
+ end
120
+ end
121
+
98
122
  context "when maxredirs" do
99
123
  context "when not set" do
100
124
  it "defaults to 50" do
@@ -195,6 +195,14 @@ describe Typhoeus::Response::Informations do
195
195
  end
196
196
  end
197
197
 
198
+ describe "#redirect_url" do
199
+ let(:options) { { :redirect_url => "http://www.example.com" } }
200
+
201
+ it "returns redirect_url from options" do
202
+ expect(response.redirect_url).to eq("http://www.example.com")
203
+ end
204
+ end
205
+
198
206
  describe "#request_size" do
199
207
  let(:options) { { :request_size => 2 } }
200
208
 
@@ -203,6 +211,38 @@ describe Typhoeus::Response::Informations do
203
211
  end
204
212
  end
205
213
 
214
+ describe "#size_upload" do
215
+ let(:options) { { :size_upload => 2.0 } }
216
+
217
+ it "returns size_upload from options" do
218
+ expect(response.size_upload).to eq(2.0)
219
+ end
220
+ end
221
+
222
+ describe "#size_download" do
223
+ let(:options) { { :size_download => 2.0 } }
224
+
225
+ it "returns size_download from options" do
226
+ expect(response.size_download).to eq(2.0)
227
+ end
228
+ end
229
+
230
+ describe "#speed_upload" do
231
+ let(:options) { { :speed_upload => 2.0 } }
232
+
233
+ it "returns speed_upload from options" do
234
+ expect(response.speed_upload).to eq(2.0)
235
+ end
236
+ end
237
+
238
+ describe "#speed_download" do
239
+ let(:options) { { :speed_download => 2.0 } }
240
+
241
+ it "returns speed_download from options" do
242
+ expect(response.speed_download).to eq(2.0)
243
+ end
244
+ end
245
+
206
246
  describe "#headers" do
207
247
  context "when no response_headers" do
208
248
  it "returns nil" do
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Balatero
8
8
  - Paul Dix
9
9
  - Hans Hasselberg
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-05-08 00:00:00.000000000 Z
13
+ date: 2023-11-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ethon
@@ -34,9 +34,10 @@ executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
+ - ".github/workflows/ci.yml"
38
+ - ".github/workflows/experimental.yml"
37
39
  - ".gitignore"
38
40
  - ".rspec"
39
- - ".travis.yml"
40
41
  - CHANGELOG.md
41
42
  - CONTRIBUTING.md
42
43
  - Gemfile
@@ -134,7 +135,7 @@ homepage: https://github.com/typhoeus/typhoeus
134
135
  licenses:
135
136
  - MIT
136
137
  metadata: {}
137
- post_install_message:
138
+ post_install_message:
138
139
  rdoc_options: []
139
140
  require_paths:
140
141
  - lib
@@ -149,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  - !ruby/object:Gem::Version
150
151
  version: 1.3.6
151
152
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.5.2.3
154
- signing_key:
153
+ rubygems_version: 3.3.7
154
+ signing_key:
155
155
  specification_version: 4
156
156
  summary: Parallel HTTP library on top of libcurl multi.
157
157
  test_files:
data/.travis.yml DELETED
@@ -1,26 +0,0 @@
1
- language: ruby
2
- script: "bundle exec rake"
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.10
7
- - 2.2.10
8
- - 2.3.8
9
- - 2.4.7
10
- - 2.5.6
11
- - 2.6.4
12
- - ruby-head
13
- - jruby-head
14
- - jruby-18mode
15
- - jruby-19mode
16
- matrix:
17
- fast_finish: true
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
21
- - rvm: ree
22
- include:
23
- - rvm: 1.8.7
24
- dist: precise
25
- - rvm: 1.9.2
26
- dist: trusty