Skip to content

Commit

Permalink
Merge pull request #265 from httprb/tonyarcieri/remove-deprecations
Browse files Browse the repository at this point in the history
Remove all deprecations (closes #208)
  • Loading branch information
tarcieri committed Nov 23, 2015
2 parents 011fcb1 + 24ca716 commit a2f568b
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 80 deletions.
16 changes: 16 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 5 additions & 32 deletions lib/http/chainable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,24 +169,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)
Expand All @@ -197,10 +188,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

Expand Down Expand Up @@ -229,21 +217,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:
Expand Down
12 changes: 6 additions & 6 deletions lib/http/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(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
Expand Down
3 changes: 0 additions & 3 deletions lib/http/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>]
Expand Down
11 changes: 1 addition & 10 deletions lib/http/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 0 additions & 3 deletions lib/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
10 changes: 0 additions & 10 deletions lib/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/http/response/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def on_body(chunk)
end

def chunk
chunk, @chunk = @chunk, nil
chunk = @chunk
@chunk = nil
chunk
end

Expand Down
3 changes: 0 additions & 3 deletions lib/http/response/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
5 changes: 2 additions & 3 deletions spec/lib/http/options_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/http/response/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit a2f568b

Please sign in to comment.