From b5b8c3cb65b3d3048fec7e0707917b6b47c0f700 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 21 Nov 2015 12:53:03 -0800 Subject: [PATCH 1/4] Remove all deprecations (closes #208) --- lib/http/chainable.rb | 32 +-------------------------- lib/http/connection.rb | 12 +++++----- lib/http/headers.rb | 3 --- lib/http/options.rb | 11 +-------- lib/http/request.rb | 3 --- lib/http/response.rb | 10 --------- lib/http/response/status.rb | 3 --- spec/lib/http/options_spec.rb | 5 ++--- spec/lib/http/response/status_spec.rb | 4 ++-- spec/lib/http_spec.rb | 6 ++--- 10 files changed, 15 insertions(+), 74 deletions(-) diff --git a/lib/http/chainable.rb b/lib/http/chainable.rb index d73e6daa..757812e9 100644 --- a/lib/http/chainable.rb +++ b/lib/http/chainable.rb @@ -166,24 +166,12 @@ def follow(opts = {}) branch default_options.with_follow opts end - # @deprecated will be removed in 1.0.0 - # @see #follow - alias_method :with_follow, :follow - # Make a request with the given headers # @param headers def headers(headers) branch default_options.with_headers(headers) end - # @deprecated will be removed in 1.0.0 - # @see #headers - alias_method :with, :headers - - # @deprecated will be removed in 1.0.0 - # @see #headers - alias_method :with_headers, :headers - # Make a request with the given cookies def cookies(cookies) branch default_options.with_cookies(cookies) @@ -197,10 +185,7 @@ def accept(type) # Make a request with the given Authorization header # @param [#to_s] value Authorization header value - def auth(value, opts = nil) - # shim for deprecated auth(:basic, opts). - # will be removed in 0.8.0 - return basic_auth(opts) if :basic == value + def auth(value) headers Headers::AUTHORIZATION => value.to_s end @@ -229,21 +214,6 @@ def default_options=(opts) @default_options = HTTP::Options.new(opts) end - # @deprecated Will be removed in 1.0.0; Use `#default_options#headers` - # Get headers of HTTP options - def default_headers - default_options.headers - end - - # Set headers of HTTP options - # @deprecated Will be removed in 1.0.0; Use `#headers` - # @param headers - def default_headers=(headers) - @default_options = default_options.dup do |opts| - opts.headers = headers - end - end - private # :nodoc: diff --git a/lib/http/connection.rb b/lib/http/connection.rb index 7daeed3d..da510875 100644 --- a/lib/http/connection.rb +++ b/lib/http/connection.rb @@ -22,15 +22,15 @@ class Connection # @param [HTTP::Options] options def initialize(req, options) @persistent = options.persistent? - @keep_alive_timeout = options[:keep_alive_timeout].to_f + @keep_alive_timeout = options.keep_alive_timeout.to_f @pending_request = false @pending_response = false @failed_proxy_connect = false @parser = Response::Parser.new - @socket = options[:timeout_class].new(options[:timeout_options]) - @socket.connect(options[:socket_class], req.socket_host, req.socket_port) + @socket = options.timeout_class.new(options.timeout_options) + @socket.connect(options.socket_class, req.socket_host, req.socket_port) send_proxy_connect_request(req) start_tls(req, options) @@ -148,14 +148,14 @@ def expired? def start_tls(req, options) return unless req.uri.https? && !failed_proxy_connect? - ssl_context = options[:ssl_context] + ssl_context = options.ssl_context unless ssl_context ssl_context = OpenSSL::SSL::SSLContext.new - ssl_context.set_params(options[:ssl] || {}) + ssl_context.set_params(Hash(options.ssl)) end - @socket.start_tls(req.uri.host, options[:ssl_socket_class], ssl_context) + @socket.start_tls(req.uri.host, options.ssl_socket_class, ssl_context) end # Open tunnel through proxy diff --git a/lib/http/headers.rb b/lib/http/headers.rb index 38724dd9..8483d59b 100644 --- a/lib/http/headers.rb +++ b/lib/http/headers.rb @@ -51,9 +51,6 @@ def add(name, value) Array(value).each { |v| @pile << [name, v.to_s] } end - # @deprecated Will be removed in 1.0.0 - alias_method :append, :add - # Returns list of header values if any. # # @return [Array] diff --git a/lib/http/options.rb b/lib/http/options.rb index becf94a2..31ec674e 100644 --- a/lib/http/options.rb +++ b/lib/http/options.rb @@ -91,15 +91,6 @@ def persistent? !persistent.nil? end - # @deprecated - def [](option) - send(option) - rescue - warn "[DEPRECATED] `HTTP::Options#[:#{option}]` was deprecated. " \ - "Use `HTTP::Options##{option}` instead." - nil - end - def merge(other) h1 = to_hash h2 = other.to_hash @@ -119,7 +110,7 @@ def merge(other) def to_hash hash_pairs = self.class. defined_options. - flat_map { |opt_name| [opt_name, self[opt_name]] } + flat_map { |opt_name| [opt_name, send(opt_name)] } Hash[*hash_pairs] end diff --git a/lib/http/request.rb b/lib/http/request.rb index 66f6e12d..1e1a55ac 100644 --- a/lib/http/request.rb +++ b/lib/http/request.rb @@ -126,9 +126,6 @@ def headline "#{verb.to_s.upcase} #{request_uri.omit :fragment} HTTP/#{version}" end - # @deprecated Will be removed in 1.0.0 - alias_method :request_header, :headline - # Compute HTTP request header SSL proxy connection def proxy_connect_header "CONNECT #{host}:#{port} HTTP/#{version}" diff --git a/lib/http/response.rb b/lib/http/response.rb index e8168d54..dc6064c4 100644 --- a/lib/http/response.rb +++ b/lib/http/response.rb @@ -14,13 +14,6 @@ class Response include HTTP::Headers::Mixin - # @deprecated Will be removed in 1.0.0 - # Use Status::REASONS - STATUS_CODES = Status::REASONS - - # @deprecated Will be removed in 1.0.0 - SYMBOL_TO_STATUS_CODE = Hash[STATUS_CODES.map { |k, v| [v.downcase.gsub(/\s|-/, "_").to_sym, k] }].freeze - # @return [Status] attr_reader :status @@ -46,9 +39,6 @@ def initialize(status, version, headers, body, uri = nil) # rubocop:disable Para # @return (see HTTP::Response::Status#code) def_delegator :status, :code - # @deprecated Will be removed in 1.0.0 - alias_method :status_code, :code - # @!method to_s # (see HTTP::Response::Body#to_s) def_delegator :body, :to_s diff --git a/lib/http/response/status.rb b/lib/http/response/status.rb index 85d605ca..6de58f06 100644 --- a/lib/http/response/status.rb +++ b/lib/http/response/status.rb @@ -91,9 +91,6 @@ def to_sym SYMBOLS[code] end - # @deprecated Will be removed in 1.0.0 - alias_method :symbolize, :to_sym - # Printable version of HTTP Status, surrounded by quote marks, # with special characters escaped. # diff --git a/spec/lib/http/options_spec.rb b/spec/lib/http/options_spec.rb index ccc39378..1ab21920 100644 --- a/spec/lib/http/options_spec.rb +++ b/spec/lib/http/options_spec.rb @@ -1,9 +1,8 @@ RSpec.describe HTTP::Options do subject { described_class.new(:response => :body) } - it "behaves like a Hash for reading" do - expect(subject[:response]).to eq(:body) - expect(subject[:nosuchone]).to be nil + it "has reader methods for attributes" do + expect(subject.response).to eq(:body) end it "coerces to a Hash" do diff --git a/spec/lib/http/response/status_spec.rb b/spec/lib/http/response/status_spec.rb index d1314a58..a0931054 100644 --- a/spec/lib/http/response/status_spec.rb +++ b/spec/lib/http/response/status_spec.rb @@ -34,8 +34,8 @@ end end - describe "#symbolize" do - subject { described_class.new(code).symbolize } + describe "#to_sym" do + subject { described_class.new(code).to_sym } context "with unknown code" do let(:code) { 1024 } diff --git a/spec/lib/http_spec.rb b/spec/lib/http_spec.rb index 3224d74a..5272c7ab 100644 --- a/spec/lib/http_spec.rb +++ b/spec/lib/http_spec.rb @@ -201,12 +201,12 @@ describe ".auth" do it "sets Authorization header to the given value" do client = HTTP.auth "abc" - expect(client.default_headers[:authorization]).to eq "abc" + expect(client.default_options.headers[:authorization]).to eq "abc" end it "accepts any #to_s object" do client = HTTP.auth double :to_s => "abc" - expect(client.default_headers[:authorization]).to eq "abc" + expect(client.default_options.headers[:authorization]).to eq "abc" end end @@ -225,7 +225,7 @@ it "sets Authorization header with proper BasicAuth value" do client = HTTP.basic_auth :user => "foo", :pass => "bar" - expect(client.default_headers[:authorization]). + expect(client.default_options.headers[:authorization]). to match(%r{^Basic [A-Za-z0-9+/]+=*$}) end end From 0cd56ac576765a135fb27286e9ec21b8abb5911b Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 21 Nov 2015 12:55:39 -0800 Subject: [PATCH 2/4] Document removed deprecations in CHANGES.md --- CHANGES.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 05147b2b..654290d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,19 @@ +## HEAD + +* [#265](https://github.com/httprb/http/pull/265/): + Remove deprecations ([@tarcieri]): + - HTTP::Chainable#with_follow (use #follow) + - HTTP::Chainable#with, #with_headers (use #headers) + - HTTP::Chainable#auth(:basic, ...) (use #basic_auth) + - HTTP::Chainable#default_headers (use #default_options[:headers]) + - HTTP::Headers#append (use #add) + - HTTP::Options#[] hash-like API deprecated in favor of explicit methods + - HTTP::Request#request_header (use #headline) + - HTTP::Response::STATUS_CODES (use HTTP::Status::REASONS) + - HTTP::Response::SYMBOL_TO_STATUS_CODE (no replacement) + - HTTP::Response#status_code (use #status or #code) + - HTTP::Response::Status#symbolize (use #to_sym) + ## 0.9.8 (2015-09-29) * [#260](https://github.com/httprb/http/pull/258): From b4b9c1d099abf25224af1e6f940e5635c96520f5 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 21 Nov 2015 13:01:14 -0800 Subject: [PATCH 3/4] Ruby 1.9.3 doesn't define Hash() :( --- lib/http/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http/connection.rb b/lib/http/connection.rb index da510875..9bdec865 100644 --- a/lib/http/connection.rb +++ b/lib/http/connection.rb @@ -152,7 +152,7 @@ def start_tls(req, options) unless ssl_context ssl_context = OpenSSL::SSL::SSLContext.new - ssl_context.set_params(Hash(options.ssl)) + ssl_context.set_params(options.ssl || {}) end @socket.start_tls(req.uri.host, options.ssl_socket_class, ssl_context) From 24ca7160e2a7a61accc17851b528e4057576fa66 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 21 Nov 2015 13:11:49 -0800 Subject: [PATCH 4/4] RuboCop fixups Also locks to the latest version of RuboCop so these sorts of random RuboCop changes don't wind up in the middle of other PRs. --- Gemfile | 8 ++++---- lib/http/chainable.rb | 5 ++++- lib/http/response/parser.rb | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index aaf7320a..aed1aa76 100644 --- a/Gemfile +++ b/Gemfile @@ -20,11 +20,11 @@ end group :test do gem "backports" gem "coveralls" - gem "simplecov", ">= 0.9" - gem "json", ">= 1.8.1" - gem "rspec", "~> 3.0" + gem "simplecov", ">= 0.9" + gem "json", ">= 1.8.1" + gem "rubocop", "= 0.35.1" + gem "rspec", "~> 3.0" gem "rspec-its" - gem "rubocop" gem "yardstick" gem "certificate_authority" end diff --git a/lib/http/chainable.rb b/lib/http/chainable.rb index 757812e9..d5fcd411 100644 --- a/lib/http/chainable.rb +++ b/lib/http/chainable.rb @@ -83,7 +83,10 @@ def request(verb, uri, options = {}) # @option options [Float] :write Write timeout # @option options [Float] :connect Connect timeout def timeout(klass, options = {}) - klass, options = :per_operation, klass if klass.is_a? Hash + if klass.is_a? Hash + options = klass + klass = :per_operation + end klass = case klass.to_sym when :null then HTTP::Timeout::Null diff --git a/lib/http/response/parser.rb b/lib/http/response/parser.rb index 53b03749..46010f56 100644 --- a/lib/http/response/parser.rb +++ b/lib/http/response/parser.rb @@ -42,7 +42,8 @@ def on_body(chunk) end def chunk - chunk, @chunk = @chunk, nil + chunk = @chunk + @chunk = nil chunk end