Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ Style/EachWithObject:
Style/Encoding:
Enabled: false

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/Lambda:
Enabled: false

Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ gem "rake"
group :development do
gem "celluloid-io"
gem "guard"
gem "guard-rspec", :require => false
gem "nokogiri", :require => false
gem "guard-rspec", require: false
gem "nokogiri", require: false
gem "pry"

platforms :ruby_19, :ruby_20 do
Expand All @@ -24,7 +24,7 @@ group :test do
gem "rspec", "~> 3.0"
gem "rspec-its"
gem "yardstick"
gem "certificate_authority", :require => false
gem "certificate_authority", require: false
end

group :doc do
Expand Down
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# More info at https://github.com/guard/guard#readme

guard :rspec, :cmd => "GUARD_RSPEC=1 bundle exec rspec --no-profile" do
guard :rspec, cmd: "GUARD_RSPEC=1 bundle exec rspec --no-profile" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new

task :test => :spec
task test: :spec

begin
require "rubocop/rake_task"
Expand Down Expand Up @@ -68,4 +68,4 @@ task :generate_status_codes do
end
end

task :default => [:spec, :rubocop, :verify_measurements]
task default: [:spec, :rubocop, :verify_measurements]
2 changes: 1 addition & 1 deletion lib/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module HTTP
extend Chainable

class << self
# HTTP[:accept => 'text/html'].get(...)
# HTTP[accept: 'text/html'].get(...)
alias [] headers
end
end
4 changes: 2 additions & 2 deletions lib/http/chainable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def timeout(klass, options = {})
end

branch default_options.merge(
:timeout_class => klass,
:timeout_options => options
timeout_class: klass,
timeout_options: options
)
end

Expand Down
24 changes: 12 additions & 12 deletions lib/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def request(verb, uri, opts = {})
proxy = opts.proxy

req = HTTP::Request.new(
:verb => verb,
:uri => uri,
:headers => headers,
:proxy => proxy,
:body => body
verb: verb,
uri: uri,
headers: headers,
proxy: proxy,
body: body
)

res = perform(req, opts)
Expand Down Expand Up @@ -68,13 +68,13 @@ def perform(req, options)
end

res = Response.new(
:status => @connection.status_code,
:version => @connection.http_version,
:headers => @connection.headers,
:proxy_headers => @connection.proxy_response_headers,
:connection => @connection,
:encoding => options.encoding,
:uri => req.uri
status: @connection.status_code,
version: @connection.http_version,
headers: @connection.headers,
proxy_headers: @connection.proxy_response_headers,
connection: @connection,
encoding: options.encoding,
uri: req.uri
)

@connection.finish_response if req.verb == :head
Expand Down
24 changes: 12 additions & 12 deletions lib/http/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ def def_option(name, &interpreter)

def initialize(options = {})
defaults = {
:response => :auto,
:proxy => {},
:timeout_class => self.class.default_timeout_class,
:timeout_options => {},
:socket_class => self.class.default_socket_class,
:nodelay => false,
:ssl_socket_class => self.class.default_ssl_socket_class,
:ssl => {},
:keep_alive_timeout => 5,
:headers => {},
:cookies => {},
:encoding => nil
response: :auto,
proxy: {},
timeout_class: self.class.default_timeout_class,
timeout_options: {},
socket_class: self.class.default_socket_class,
nodelay: false,
ssl_socket_class: self.class.default_ssl_socket_class,
ssl: {},
keep_alive_timeout: 5,
headers: {},
cookies: {},
encoding: nil
}

opts_w_defaults = defaults.merge(options)
Expand Down
30 changes: 15 additions & 15 deletions lib/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class UnsupportedSchemeError < RequestError; end

# Default ports of supported schemes
PORTS = {
:http => 80,
:https => 443,
:ws => 80,
:wss => 443
http: 80,
https: 443,
ws: 80,
wss: 443
}.freeze

# Method is given as a lowercase symbol e.g. :get, :post
Expand Down Expand Up @@ -92,12 +92,12 @@ def initialize(opts)
# Returns new Request with updated uri
def redirect(uri, verb = @verb)
req = self.class.new(
:verb => verb,
:uri => @uri.join(uri),
:headers => headers,
:proxy => proxy,
:body => body,
:version => version
verb: verb,
uri: @uri.join(uri),
headers: headers,
proxy: proxy,
body: body,
version: version
)

req[Headers::HOST] = req.uri.host
Expand Down Expand Up @@ -195,11 +195,11 @@ def normalize_uri(uri)
uri = HTTP::URI.parse uri

HTTP::URI.new(
:scheme => uri.normalized_scheme,
:authority => uri.normalized_authority,
:path => uri.normalized_path,
:query => uri.query,
:fragment => uri.normalized_fragment
scheme: uri.normalized_scheme,
authority: uri.normalized_authority,
path: uri.normalized_path,
query: uri.query,
fragment: uri.normalized_fragment
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/http/timeout/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def write_nonblock(data)
end
else
def read_nonblock(size)
@socket.read_nonblock(size, :exception => false)
@socket.read_nonblock(size, exception: false)
end

def write_nonblock(data)
@socket.write_nonblock(data, :exception => false)
@socket.write_nonblock(data, exception: false)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/http/timeout/per_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def write(data)
# Read data from the socket
def readpartial(size)
loop do
result = @socket.read_nonblock(size, :exception => false)
result = @socket.read_nonblock(size, exception: false)

return :eof if result.nil?
return result if result != :wait_readable
Expand All @@ -73,7 +73,7 @@ def readpartial(size)
# Write data to the socket
def write(data)
loop do
result = @socket.write_nonblock(data, :exception => false)
result = @socket.write_nonblock(data, exception: false)
return result unless result == :wait_writable

unless IO.select(nil, [@socket], nil, write_timeout)
Expand Down
42 changes: 21 additions & 21 deletions spec/lib/http/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ def stub(stubs)

def redirect_response(location, status = 302)
HTTP::Response.new(
:status => status,
:version => "1.1",
:headers => {"Location" => location},
:body => ""
status: status,
version: "1.1",
headers: {"Location" => location},
body: ""
)
end

def simple_response(body, status = 200)
HTTP::Response.new(
:status => status,
:version => "1.1",
:body => body
status: status,
version: "1.1",
body: body
)
end

describe "following redirects" do
it "returns response of new location" do
client = StubbedClient.new(:follow => true).stub(
client = StubbedClient.new(follow: true).stub(
"http://example.com/" => redirect_response("http://example.com/blog"),
"http://example.com/blog" => simple_response("OK")
)
Expand All @@ -53,7 +53,7 @@ def simple_response(body, status = 200)
end

it "prepends previous request uri scheme and host if needed" do
client = StubbedClient.new(:follow => true).stub(
client = StubbedClient.new(follow: true).stub(
"http://example.com/" => redirect_response("/index"),
"http://example.com/index" => redirect_response("/index.html"),
"http://example.com/index.html" => simple_response("OK")
Expand All @@ -63,7 +63,7 @@ def simple_response(body, status = 200)
end

it "fails upon endless redirects" do
client = StubbedClient.new(:follow => true).stub(
client = StubbedClient.new(follow: true).stub(
"http://example.com/" => redirect_response("/")
)

Expand All @@ -72,7 +72,7 @@ def simple_response(body, status = 200)
end

it "fails if max amount of hops reached" do
client = StubbedClient.new(:follow => {:max_hops => 5}).stub(
client = StubbedClient.new(follow: {max_hops: 5}).stub(
"http://example.com/" => redirect_response("/1"),
"http://example.com/1" => redirect_response("/2"),
"http://example.com/2" => redirect_response("/3"),
Expand All @@ -88,7 +88,7 @@ def simple_response(body, status = 200)

context "with non-ASCII URLs" do
it "theoretically works like a charm" do
client = StubbedClient.new(:follow => true).stub(
client = StubbedClient.new(follow: true).stub(
"http://example.com/" => redirect_response("/könig"),
"http://example.com/könig" => simple_response("OK")
)
Expand Down Expand Up @@ -121,15 +121,15 @@ def simple_response(body, status = 200)
expect(CGI.parse(opts[:uri].query)).to eq("foo" => %w(bar), "baz" => %w(quux))
end

client.get("http://example.com/?foo=bar", :params => {:baz => "quux"})
client.get("http://example.com/?foo=bar", params: {baz: "quux"})
end

it "merges duplicate values" do
expect(HTTP::Request).to receive(:new) do |opts|
expect(opts[:uri].query).to match(/^(a=1&a=2|a=2&a=1)$/)
end

client.get("http://example.com/?a=1", :params => {:a => 2})
client.get("http://example.com/?a=1", params: {a: 2})
end

it "does not modifies query part if no params were given" do
Expand All @@ -145,15 +145,15 @@ def simple_response(body, status = 200)
expect(CGI.parse(opts[:uri].query)).to eq "a[]" => %w(b c), "d" => %w(e)
end

client.get("http://example.com/?a[]=b&a[]=c", :params => {:d => "e"})
client.get("http://example.com/?a[]=b&a[]=c", params: {d: "e"})
end

it "properly encodes colons" do
expect(HTTP::Request).to receive(:new) do |opts|
expect(opts[:uri].query).to eq "t=1970-01-01T00%3A00%3A00Z"
end

client.get("http://example.com/", :params => {:t => "1970-01-01T00:00:00Z"})
client.get("http://example.com/", params: {t: "1970-01-01T00:00:00Z"})
end
end

Expand All @@ -166,7 +166,7 @@ def simple_response(body, status = 200)
expect(opts[:body]).to eq '{"foo":"bar"}'
end

client.get("http://example.com/", :json => {:foo => :bar})
client.get("http://example.com/", json: {foo: :bar})
end
end

Expand All @@ -186,7 +186,7 @@ def simple_response(body, status = 200)

context "with explicitly given `Host` header" do
let(:headers) { {"Host" => "another.example.com"} }
let(:client) { described_class.new :headers => headers }
let(:client) { described_class.new headers: headers }

it "keeps `Host` header as is" do
expect(client).to receive(:perform) do |req, _|
Expand All @@ -206,12 +206,12 @@ def simple_response(body, status = 200)
end

describe "working with SSL" do
run_server(:dummy_ssl) { DummyServer.new(:ssl => true) }
run_server(:dummy_ssl) { DummyServer.new(ssl: true) }

let(:extra_options) { {} }

let(:client) do
described_class.new options.merge(:ssl_context => SSLHelper.client_context).merge(extra_options)
described_class.new options.merge(ssl_context: SSLHelper.client_context).merge(extra_options)
end

include_context "HTTP handling" do
Expand All @@ -230,7 +230,7 @@ def simple_response(body, status = 200)

context "with SSL options instead of a context" do
let(:client) do
described_class.new options.merge :ssl => SSLHelper.client_params
described_class.new options.merge ssl: SSLHelper.client_params
end

it "just works" do
Expand Down
Loading