summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSruthi Chandran <srud@disroot.org>2016-09-09 18:29:28 +0530
committerSruthi Chandran <srud@disroot.org>2016-09-09 18:29:28 +0530
commitaa2ec24231733e66d7a000e7d496e193bf73596a (patch)
treecfa5d8a9effbd5855b1bd1e2fb1624acb3bf686d
parent13c145bd5404dd8d320b4dd85e55f11fe5d93d98 (diff)
parentce9bc5c4cb7fffbea6c0e94b126ee036487780bc (diff)
Merge tag 'upstream/1.1.0'
Upstream version 1.1.0
-rw-r--r--.travis.yml1
-rw-r--r--CHANGELOG.md10
-rw-r--r--Gemfile5
-rw-r--r--README.md13
-rw-r--r--lib/typhoeus/adapters/faraday.rb1
-rw-r--r--lib/typhoeus/config.rb7
-rw-r--r--lib/typhoeus/request.rb2
-rw-r--r--lib/typhoeus/response/header.rb1
-rw-r--r--lib/typhoeus/version.rb2
-rw-r--r--spec/typhoeus/adapters/faraday_spec.rb31
-rw-r--r--spec/typhoeus/config_spec.rb2
-rw-r--r--spec/typhoeus/request_spec.rb24
-rw-r--r--spec/typhoeus/response/header_spec.rb13
13 files changed, 91 insertions, 21 deletions
diff --git a/.travis.yml b/.travis.yml
index d27a485..0f720c3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,3 +21,4 @@ matrix:
- rvm: ruby-head
- rvm: jruby-head
- rvm: ree
+ - rvm: rbx
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0ba9a7..471cb4f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,15 @@
## Master
-[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.0.2...master)
+[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.1.0...master)
+
+## 1.1.0
+
+[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.0.2...v1.1.0)
+
+* Unless specified `Expect` header is set to be empty to avoid `100 continue`
+ to be set when using `PUT`
+* Add global config option `Typhoeus::Config.proxy`
## 1.0.2
diff --git a/Gemfile b/Gemfile
index 3ab5a3a..3925c9b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,9 +1,11 @@
source "https://rubygems.org"
gemspec
-if Gem.ruby_version < Gem::Version.new("1.9.3")
+if Gem.ruby_version < Gem::Version.new("2.0.0")
gem "rake", "< 11"
+ gem "json", "< 2"
else
+ gem "json"
gem "rake"
end
@@ -11,7 +13,6 @@ group :development, :test do
gem "rspec", "~> 3.0"
gem "sinatra", "~> 1.3"
- gem "json"
gem "faraday", ">= 0.9"
if RUBY_PLATFORM == "java"
diff --git a/README.md b/README.md
index 0d93b04..5c502da 100644
--- a/README.md
+++ b/README.md
@@ -2,16 +2,6 @@
Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
-# Typhoeus needs your help!
-
-I don't have enough time, but I think this is a nice project! If you or your company is using Typhoeus you should help keeping it alive! Pick any of:
-
-* add docs
-* respond to issues
-* add features
-
-Or send me an email! I would be more than happy to help getting you up to speed!
-
## Example
A single request:
@@ -554,6 +544,3 @@ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
-
-
-[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/typhoeus/typhoeus/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
diff --git a/lib/typhoeus/adapters/faraday.rb b/lib/typhoeus/adapters/faraday.rb
index 4f6f587..ba3d857 100644
--- a/lib/typhoeus/adapters/faraday.rb
+++ b/lib/typhoeus/adapters/faraday.rb
@@ -92,6 +92,7 @@ module Faraday # :nodoc:
end
elsif resp.response_code == 0
env[:typhoeus_connection_failed] = true
+ env[:typhoeus_return_message] = resp.return_message
unless parallel?(env)
raise Faraday::Error::ConnectionFailed, resp.return_message
end
diff --git a/lib/typhoeus/config.rb b/lib/typhoeus/config.rb
index 09ca714..32beff2 100644
--- a/lib/typhoeus/config.rb
+++ b/lib/typhoeus/config.rb
@@ -58,5 +58,12 @@ module Typhoeus
#
# @see Typhoeus::Request#set_defaults
attr_accessor :user_agent
+
+ # Defines wether to use a proxy server for every request.
+ #
+ # @return [ String ]
+ #
+ # @see Typhoeus::Request#set_defaults
+ attr_accessor :proxy
end
end
diff --git a/lib/typhoeus/request.rb b/lib/typhoeus/request.rb
index a29eed1..c41ee7b 100644
--- a/lib/typhoeus/request.rb
+++ b/lib/typhoeus/request.rb
@@ -212,8 +212,10 @@ module Typhoeus
default_user_agent = Config.user_agent || Typhoeus::USER_AGENT
options[:headers] = {'User-Agent' => default_user_agent}.merge(options[:headers] || {})
+ options[:headers]['Expect'] ||= ''
options[:verbose] = Typhoeus::Config.verbose if options[:verbose].nil? && !Typhoeus::Config.verbose.nil?
options[:maxredirs] ||= 50
+ options[:proxy] = Typhoeus::Config.proxy unless options.has_key?(:proxy) || Typhoeus::Config.proxy.nil?
end
end
end
diff --git a/lib/typhoeus/response/header.rb b/lib/typhoeus/response/header.rb
index 3c18e19..8ec96d1 100644
--- a/lib/typhoeus/response/header.rb
+++ b/lib/typhoeus/response/header.rb
@@ -33,6 +33,7 @@ module Typhoeus
end
when String
raw.lines.each do |header|
+ header.strip!
next if header.empty? || header.start_with?( 'HTTP/1.' )
process_line(header)
end
diff --git a/lib/typhoeus/version.rb b/lib/typhoeus/version.rb
index 7f5d4dc..708c0a5 100644
--- a/lib/typhoeus/version.rb
+++ b/lib/typhoeus/version.rb
@@ -1,5 +1,5 @@
module Typhoeus
# The current Typhoeus version.
- VERSION = '1.0.2'
+ VERSION = '1.1.0'
end
diff --git a/spec/typhoeus/adapters/faraday_spec.rb b/spec/typhoeus/adapters/faraday_spec.rb
index cc43934..a6809ef 100644
--- a/spec/typhoeus/adapters/faraday_spec.rb
+++ b/spec/typhoeus/adapters/faraday_spec.rb
@@ -123,6 +123,37 @@ describe Faraday::Adapter::Typhoeus do
end
end
+ context "when the connection failed" do
+ before do
+ stub = Typhoeus::Response.new \
+ :response_code => 0,
+ :return_code => 0,
+ :mock => true
+
+ Typhoeus.stub(base_url + '/').and_return(stub)
+ end
+
+ context "when parallel" do
+ it "isn't successful" do
+ response = nil
+ conn.in_parallel { response = conn.get("/") }
+ expect(response.success?).to be_falsey
+ end
+
+ it "translates the response code into an error message" do
+ response = nil
+ conn.in_parallel { response = conn.get("/") }
+ expect(response.env[:typhoeus_return_message]).to eq("No error")
+ end
+ end
+
+ context "when not parallel" do
+ it "raises an error" do
+ expect { conn.get("/") }.to raise_error(Faraday::Error::ConnectionFailed, "No error")
+ end
+ end
+ end
+
describe "#configure_socket" do
let(:env) { { :request => { :bind => { :host => "interface" } } } }
diff --git a/spec/typhoeus/config_spec.rb b/spec/typhoeus/config_spec.rb
index c67d256..ac721c5 100644
--- a/spec/typhoeus/config_spec.rb
+++ b/spec/typhoeus/config_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Typhoeus::Config do
let(:config) { Typhoeus::Config }
- [:block_connection, :memoize, :verbose, :cache, :user_agent].each do |name|
+ [:block_connection, :memoize, :verbose, :cache, :user_agent, :proxy].each do |name|
it "responds to #{name}" do
expect(config).to respond_to(name)
end
diff --git a/spec/typhoeus/request_spec.rb b/spec/typhoeus/request_spec.rb
index 2072393..cabcb4c 100644
--- a/spec/typhoeus/request_spec.rb
+++ b/spec/typhoeus/request_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Typhoeus::Request do
let(:base_url) { "localhost:3001" }
- let(:options) { {:verbose => true, :headers => { 'User-Agent' => "Fubar" }, :maxredirs => 50} }
+ let(:options) { {:verbose => true, :headers => { 'User-Agent' => "Fubar", 'Expect' => "" }, :maxredirs => 50} }
let(:request) { Typhoeus::Request.new(base_url, options) }
describe ".url" do
@@ -110,6 +110,23 @@ describe Typhoeus::Request do
end
end
end
+
+ context "when Config.proxy set" do
+ before { Typhoeus.configure { |config| config.proxy = "http://proxy.internal" } }
+ after { Typhoeus.configure { |config| config.proxy = nil } }
+
+ it "respects" do
+ expect(request.options[:proxy]).to eq("http://proxy.internal")
+ end
+
+ context "when option proxy set" do
+ let(:options) { {:proxy => nil} }
+
+ it "does not override" do
+ expect(request.options[:proxy]).to be_nil
+ end
+ end
+ end
end
describe "#eql?" do
@@ -150,7 +167,7 @@ describe Typhoeus::Request do
context "when different order" do
let(:other_options) {
- {:headers => { 'User-Agent' => "Fubar" }, :verbose => true }
+ {:headers => { 'User-Agent' => "Fubar", 'Expect' => ""}, :verbose => true }
}
let(:other) { Typhoeus::Request.new(base_url, other_options)}
@@ -166,7 +183,7 @@ describe Typhoeus::Request do
context "when request.eql?(other)" do
context "when different order" do
let(:other_options) {
- {:headers => { 'User-Agent' => "Fubar" }, :verbose => true }
+ {:headers => { 'User-Agent' => "Fubar", 'Expect' => "" }, :verbose => true }
}
let(:other) { Typhoeus::Request.new(base_url, other_options)}
@@ -211,4 +228,5 @@ describe Typhoeus::Request do
expect(request.encoded_body).to eq("a=1")
end
end
+
end
diff --git a/spec/typhoeus/response/header_spec.rb b/spec/typhoeus/response/header_spec.rb
index b345825..8dd4d5a 100644
--- a/spec/typhoeus/response/header_spec.rb
+++ b/spec/typhoeus/response/header_spec.rb
@@ -92,6 +92,19 @@ describe Typhoeus::Response::Header do
expect(header[name.downcase]).to eq(value)
end
end
+
+ context 'includes line with only whitespace' do
+ let(:raw) do
+ 'HTTP/1.1 200 OK
+ Date: Fri, 29 Jun 2012 10:09:23 GMT
+
+'
+ end
+
+ it 'ignores it' do
+ expect(header).to eq({ 'Date' => 'Fri, 29 Jun 2012 10:09:23 GMT' })
+ end
+ end
end
end
end