Skip to content
Merged
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: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Style/EachWithObject:
Style/Encoding:
Enabled: false

Style/EmptyCaseCondition:
Enabled: false

Style/HashSyntax:
EnforcedStyle: hash_rockets

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ group :test do
gem "coveralls"
gem "simplecov", ">= 0.9"
gem "json", ">= 1.8.1"
gem "rubocop", "= 0.39.0"
gem "rubocop", "= 0.40.0"
gem "rspec", "~> 3.0"
gem "rspec-its"
gem "yardstick"
Expand Down
1 change: 1 addition & 0 deletions lib/http.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "http/parser"

require "http/errors"
Expand Down
1 change: 1 addition & 0 deletions lib/http/content_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module HTTP
ContentType = Struct.new(:mime_type, :charset) do
MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)}
Expand Down
1 change: 1 addition & 0 deletions lib/http/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module HTTP
# Generic error
class Error < StandardError; end
Expand Down
1 change: 1 addition & 0 deletions lib/http/headers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "forwardable"

require "http/errors"
Expand Down
1 change: 1 addition & 0 deletions lib/http/headers/mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "forwardable"

module HTTP
Expand Down
1 change: 1 addition & 0 deletions lib/http/mime_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module HTTP
# MIME type encode/decode adapters
module MimeType
Expand Down
1 change: 1 addition & 0 deletions lib/http/mime_type/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "forwardable"
require "singleton"

Expand Down
1 change: 1 addition & 0 deletions lib/http/mime_type/json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "json"
require "http/mime_type/adapter"

Expand Down
1 change: 1 addition & 0 deletions lib/http/options.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "http/headers"
require "openssl"
require "socket"
Expand Down
1 change: 1 addition & 0 deletions lib/http/redirector.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "set"

require "http/headers"
Expand Down
1 change: 1 addition & 0 deletions lib/http/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "forwardable"

require "http/headers"
Expand Down
6 changes: 4 additions & 2 deletions lib/http/response/body.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "forwardable"
require "http/client"

Expand Down Expand Up @@ -43,8 +44,9 @@ def to_s
end

begin
@streaming = false
@contents = "".force_encoding(encoding)
@streaming = false
@contents = String.new("").force_encoding(encoding)

while (chunk = @client.readpartial)
@contents << chunk.force_encoding(encoding)
end
Expand Down
1 change: 1 addition & 0 deletions lib/http/response/parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module HTTP
class Response
class Parser
Expand Down
1 change: 1 addition & 0 deletions lib/http/response/status.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "delegate"

require "http/response/status/reasons"
Expand Down
1 change: 1 addition & 0 deletions lib/http/response/status/reasons.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# AUTO-GENERATED FILE, DO NOT CHANGE IT MANUALLY

require "delegate"
Expand Down
1 change: 1 addition & 0 deletions lib/http/timeout/global.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "timeout"
require "io/wait"

Expand Down
1 change: 1 addition & 0 deletions lib/http/timeout/null.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "forwardable"
require "io/wait"

Expand Down
1 change: 1 addition & 0 deletions lib/http/timeout/per_operation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "timeout"

require "http/timeout/null"
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# coding: utf-8

require "support/http_handling_shared"
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/content_type_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::ContentType do
describe ".parse" do
context "with text/plain" do
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/headers/mixin_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Headers::Mixin do
let :dummy_class do
Class.new do
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/headers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Headers do
subject(:headers) { described_class.new }

Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/options/body_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Options, "body" do
let(:opts) { HTTP::Options.new }

Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/options/form_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Options, "form" do
let(:opts) { HTTP::Options.new }

Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/options/headers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Options, "headers" do
let(:opts) { HTTP::Options.new }

Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/options/json_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Options, "json" do
let(:opts) { HTTP::Options.new }

Expand Down
44 changes: 24 additions & 20 deletions spec/lib/http/options/merge_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

RSpec.describe HTTP::Options, "merge" do
let(:opts) { HTTP::Options.new }
Expand All @@ -23,7 +24,8 @@
:body => "body-foo",
:json => {:foo => "foo"},
:headers => {:accept => "json", :foo => "foo"},
:proxy => {})
:proxy => {}
)

bar = HTTP::Options.new(
:response => :parsed_body,
Expand All @@ -36,27 +38,29 @@
:headers => {:accept => "xml", :bar => "bar"},
:timeout_options => {:foo => :bar},
:ssl => {:foo => "bar"},
:proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080})
:proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080}
)

expect(foo.merge(bar).to_hash).to eq(
:response => :parsed_body,
:timeout_class => described_class.default_timeout_class,
:timeout_options => {:foo => :bar},
:params => {:plop => "plip"},
:form => {:bar => "bar"},
:body => "body-bar",
:json => {:bar => "bar"},
:persistent => "https://www.googe.com",
:response => :parsed_body,
:timeout_class => described_class.default_timeout_class,
:timeout_options => {:foo => :bar},
:params => {:plop => "plip"},
:form => {:bar => "bar"},
:body => "body-bar",
:json => {:bar => "bar"},
:persistent => "https://www.googe.com",
:keep_alive_timeout => 10,
:ssl => {:foo => "bar"},
:headers => {"Foo" => "foo", "Accept" => "xml", "Bar" => "bar"},
:proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080},
:follow => nil,
:socket_class => described_class.default_socket_class,
:nodelay => false,
:ssl_socket_class => described_class.default_ssl_socket_class,
:ssl_context => nil,
:cookies => {},
:encoding => nil)
:ssl => {:foo => "bar"},
:headers => {"Foo" => "foo", "Accept" => "xml", "Bar" => "bar"},
:proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080},
:follow => nil,
:socket_class => described_class.default_socket_class,
:nodelay => false,
:ssl_socket_class => described_class.default_ssl_socket_class,
:ssl_context => nil,
:cookies => {},
:encoding => nil
)
end
end
1 change: 1 addition & 0 deletions spec/lib/http/options/new_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Options, "new" do
it "supports a Options instance" do
opts = HTTP::Options.new
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/options/proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Options, "proxy" do
let(:opts) { HTTP::Options.new }

Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/options_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Options do
subject { described_class.new(:response => :body) }

Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/redirector_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Redirector do
def simple_response(status, body = "", headers = {})
HTTP::Response.new(
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/request/writer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# coding: utf-8

RSpec.describe HTTP::Request::Writer do
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# coding: utf-8

RSpec.describe HTTP::Request do
Expand Down
9 changes: 5 additions & 4 deletions spec/lib/http/response/body_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# frozen_string_literal: true
RSpec.describe HTTP::Response::Body do
let(:client) { double(:sequence_id => 0) }
let(:chunks) { ["Hello, ", "World!"] }
let(:chunks) { [String.new("Hello, "), String.new("World!")] }

before { allow(client).to receive(:readpartial) { chunks.shift } }

subject(:body) { described_class.new client, Encoding::UTF_8 }
subject(:body) { described_class.new(client, Encoding::UTF_8) }

it "streams bodies from responses" do
expect(subject.to_s).to eq "Hello, World!"
expect(subject.to_s).to eq("Hello, World!")
end

context "when body empty" do
let(:chunks) { [""] }
let(:chunks) { [String.new("")] }

it "returns responds to empty? with true" do
expect(subject).to be_empty
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/response/status_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Response::Status do
describe ".new" do
it "fails if given value does not respond to #to_i" do
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/response_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::Response do
let(:body) { "Hello world!" }
let(:uri) { "http://example.com/" }
Expand Down
1 change: 1 addition & 0 deletions spec/lib/http/uri_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.describe HTTP::URI do
let(:example_http_uri_string) { "http://example.com" }
let(:example_https_uri_string) { "https://example.com" }
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/http_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true
# encoding: utf-8

require "json"

Expand Down
1 change: 1 addition & 0 deletions spec/regression_specs.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"

RSpec.describe "Regression testing" do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# coding: utf-8

require "simplecov"
Expand Down
1 change: 1 addition & 0 deletions spec/support/black_hole.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module BlackHole
def self.method_missing(*)
self
Expand Down
1 change: 1 addition & 0 deletions spec/support/capture_warning.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
def capture_warning
old_stderr = $stderr
$stderr = StringIO.new
Expand Down
1 change: 1 addition & 0 deletions spec/support/dummy_server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "webrick"
require "webrick/ssl"

Expand Down
1 change: 1 addition & 0 deletions spec/support/dummy_server/servlet.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# encoding: UTF-8

class DummyServer < WEBrick::HTTPServer
Expand Down
1 change: 1 addition & 0 deletions spec/support/http_handling_shared.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
RSpec.shared_context "HTTP handling" do
describe "timeouts" do
let(:conn_timeout) { 1 }
Expand Down
1 change: 1 addition & 0 deletions spec/support/proxy_server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "webrick/httpproxy"

require "support/black_hole"
Expand Down
1 change: 1 addition & 0 deletions spec/support/servers/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ServerConfig
def addr
config[:BindAddress]
Expand Down
1 change: 1 addition & 0 deletions spec/support/servers/runner.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ServerRunner
def run_server(name)
let! name do
Expand Down
1 change: 1 addition & 0 deletions spec/support/ssl_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "pathname"

require "certificate_authority"
Expand Down