Skip to content

Commit

Permalink
Place the dot on the line with the receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 23, 2015
1 parent 0ff9e37 commit 110a338
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -37,7 +37,7 @@ Style/Documentation:
Enabled: false

Style/DotPosition:
EnforcedStyle: leading
EnforcedStyle: trailing

Style/DoubleNegation:
Enabled: false
Expand Down
16 changes: 8 additions & 8 deletions lib/http/cache/headers.rb
Expand Up @@ -69,9 +69,9 @@ def matches?(pattern)
# ---
# Some servers send a "Expire: -1" header which must be treated as expired
def seconds_til_expires
get("Expires")
.map { |e| http_date_to_ttl(e) }
.max
get("Expires").
map { |e| http_date_to_ttl(e) }.
max
end

def http_date_to_ttl(t_str)
Expand All @@ -89,11 +89,11 @@ def to_time_or_epoch(t_str)

# @return [Numeric] the value of the max-age component of cache control
def explicit_max_age
get("Cache-Control")
.map { |v| (/max-age=(\d+)/i).match(v) }
.compact
.map { |m| m[1].to_i }
.max
get("Cache-Control").
map { |v| (/max-age=(\d+)/i).match(v) }.
compact.
map { |m| m[1].to_i }.
max
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/http/options.rb
Expand Up @@ -118,9 +118,9 @@ def merge(other)
end

def to_hash
hash_pairs = self.class
.defined_options
.flat_map { |opt_name| [opt_name, self[opt_name]] }
hash_pairs = self.class.
defined_options.
flat_map { |opt_name| [opt_name, self[opt_name]] }
Hash[*hash_pairs]
end

Expand Down
8 changes: 4 additions & 4 deletions lib/http/request/caching.rb
Expand Up @@ -80,11 +80,11 @@ def env
def conditional_headers_for(cached_response)
headers = HTTP::Headers.new

cached_response.headers.get("Etag")
.each { |etag| headers.add("If-None-Match", etag) }
cached_response.headers.get("Etag").
each { |etag| headers.add("If-None-Match", etag) }

cached_response.headers.get("Last-Modified")
.each { |last_mod| headers.add("If-Modified-Since", last_mod) }
cached_response.headers.get("Last-Modified").
each { |last_mod| headers.add("If-Modified-Since", last_mod) }

headers.add("Cache-Control", "max-age=0") if cache_headers.forces_revalidation?

Expand Down
6 changes: 3 additions & 3 deletions lib/http/response/caching.rb
Expand Up @@ -123,9 +123,9 @@ def vary

# @return [Time] the time at which the server generated this response.
def server_response_time
headers.get("Date")
.map(&method(:to_time_or_epoch))
.max || begin
headers.get("Date").
map(&method(:to_time_or_epoch)).
max || begin
# set it if it is not already set
headers["Date"] = received_at.httpdate
received_at
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/http/cache_spec.rb
Expand Up @@ -6,8 +6,8 @@
subject { described_class }

it "allows metastore and entitystore" do
expect(subject.new(:metastore => "heap:/", :entitystore => "heap:/"))
.to be_kind_of HTTP::Cache
expect(subject.new(:metastore => "heap:/", :entitystore => "heap:/")).
to be_kind_of HTTP::Cache
end
end

Expand Down Expand Up @@ -151,10 +151,10 @@

it "makes request with conditional request headers" do
subject.perform(request, opts) do |actual_request, _|
expect(actual_request.headers["If-None-Match"])
.to eq cached_response.headers["Etag"]
expect(actual_request.headers["If-Modified-Since"])
.to eq cached_response.headers["Last-Modified"]
expect(actual_request.headers["If-None-Match"]).
to eq cached_response.headers["Etag"]
expect(actual_request.headers["If-Modified-Since"]).
to eq cached_response.headers["Last-Modified"]

origin_response
end
Expand Down
26 changes: 13 additions & 13 deletions spec/lib/http/client_spec.rb
Expand Up @@ -60,8 +60,8 @@ def simple_response(body, status = 200)
"http://example.com/" => redirect_response("/")
)

expect { client.get("http://example.com/") }
.to raise_error(HTTP::Redirector::EndlessRedirectError)
expect { client.get("http://example.com/") }.
to raise_error(HTTP::Redirector::EndlessRedirectError)
end

it "fails if max amount of hops reached" do
Expand All @@ -75,8 +75,8 @@ def simple_response(body, status = 200)
"http://example.com/6" => simple_response("OK")
)

expect { client.get("http://example.com/") }
.to raise_error(HTTP::Redirector::TooManyRedirectsError)
expect { client.get("http://example.com/") }.
to raise_error(HTTP::Redirector::TooManyRedirectsError)
end

context "with non-ASCII URLs" do
Expand All @@ -103,17 +103,17 @@ def simple_response(body, status = 200)
it "returns cached responses if they exist" do
cached_response = simple_response("cached").caching
StubbedClient.new(:cache =>
HTTP::Cache.new(:metastore => "heap:/", :entitystore => "heap:/"))
.stub("http://example.com/#{sn}" => cached_response)
.get("http://example.com/#{sn}")
HTTP::Cache.new(:metastore => "heap:/", :entitystore => "heap:/")).
stub("http://example.com/#{sn}" => cached_response).
get("http://example.com/#{sn}")

# cache is now warm

client = StubbedClient.new(:cache => HTTP::Cache.new(:metastore => "heap:/", :entitystore => "heap:/"))
.stub("http://example.com/#{sn}" => simple_response("OK"))
client = StubbedClient.new(:cache => HTTP::Cache.new(:metastore => "heap:/", :entitystore => "heap:/")).
stub("http://example.com/#{sn}" => simple_response("OK"))

expect(client.get("http://example.com/#{sn}").body.to_s)
.to eq cached_response.body.to_s
expect(client.get("http://example.com/#{sn}").body.to_s).
to eq cached_response.body.to_s
end
end

Expand Down Expand Up @@ -226,8 +226,8 @@ def simple_response(body, status = 200)
end

it "fails with OpenSSL::SSL::SSLError if host mismatch" do
expect { client.get(dummy_ssl.endpoint.gsub("127.0.0.1", "localhost")) }
.to raise_error(OpenSSL::SSL::SSLError, /does not match/)
expect { client.get(dummy_ssl.endpoint.gsub("127.0.0.1", "localhost")) }.
to raise_error(OpenSSL::SSL::SSLError, /does not match/)
end

context "with SSL options instead of a context" do
Expand Down
32 changes: 16 additions & 16 deletions spec/lib/http/headers_spec.rb
Expand Up @@ -29,13 +29,13 @@
end

it "fails with empty header name" do
expect { headers.set "", "foo bar" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.set "", "foo bar" }.
to raise_error HTTP::InvalidHeaderNameError
end

it "fails with invalid header name" do
expect { headers.set "foo bar", "baz" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.set "foo bar", "baz" }.
to raise_error HTTP::InvalidHeaderNameError
end
end

Expand Down Expand Up @@ -77,13 +77,13 @@
end

it "fails with empty header name" do
expect { headers.delete "" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.delete "" }.
to raise_error HTTP::InvalidHeaderNameError
end

it "fails with invalid header name" do
expect { headers.delete "foo bar" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.delete "foo bar" }.
to raise_error HTTP::InvalidHeaderNameError
end
end

Expand Down Expand Up @@ -111,13 +111,13 @@
end

it "fails with empty header name" do
expect { headers.add "", "foobar" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.add "", "foobar" }.
to raise_error HTTP::InvalidHeaderNameError
end

it "fails with invalid header name" do
expect { headers.add "foo bar", "baz" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.add "foo bar", "baz" }.
to raise_error HTTP::InvalidHeaderNameError
end
end

Expand All @@ -139,13 +139,13 @@
end

it "fails with empty header name" do
expect { headers.get "" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.get "" }.
to raise_error HTTP::InvalidHeaderNameError
end

it "fails with invalid header name" do
expect { headers.get "foo bar" }
.to raise_error HTTP::InvalidHeaderNameError
expect { headers.get "foo bar" }.
to raise_error HTTP::InvalidHeaderNameError
end
end

Expand Down
48 changes: 24 additions & 24 deletions spec/lib/http/redirector_spec.rb
Expand Up @@ -33,24 +33,24 @@ def redirect_response(status, location)
req = HTTP::Request.new :head, "http://example.com"
res = proc { |prev_req| redirect_response(301, "#{prev_req.uri}/1") }

expect { redirector.perform(req, res.call(req), &res) }
.to raise_error HTTP::Redirector::TooManyRedirectsError
expect { redirector.perform(req, res.call(req), &res) }.
to raise_error HTTP::Redirector::TooManyRedirectsError
end

it "fails with EndlessRedirectError if endless loop detected" do
req = HTTP::Request.new :head, "http://example.com"
res = redirect_response(301, req.uri)

expect { redirector.perform(req, res) { res } }
.to raise_error HTTP::Redirector::EndlessRedirectError
expect { redirector.perform(req, res) { res } }.
to raise_error HTTP::Redirector::EndlessRedirectError
end

it "fails with StateError if there were no Location header" do
req = HTTP::Request.new :head, "http://example.com"
res = simple_response(301)

expect { |b| redirector.perform(req, res, &b) }
.to raise_error HTTP::StateError
expect { |b| redirector.perform(req, res, &b) }.
to raise_error HTTP::StateError
end

it "returns first non-redirect response" do
Expand Down Expand Up @@ -86,24 +86,24 @@ def redirect_response(status, location)
req = HTTP::Request.new :put, "http://example.com"
res = redirect_response 300, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end

it "raises StateError if original request was POST" do
req = HTTP::Request.new :post, "http://example.com"
res = redirect_response 300, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end

it "raises StateError if original request was DELETE" do
req = HTTP::Request.new :delete, "http://example.com"
res = redirect_response 300, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end
end

Expand Down Expand Up @@ -170,24 +170,24 @@ def redirect_response(status, location)
req = HTTP::Request.new :put, "http://example.com"
res = redirect_response 301, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end

it "raises StateError if original request was POST" do
req = HTTP::Request.new :post, "http://example.com"
res = redirect_response 301, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end

it "raises StateError if original request was DELETE" do
req = HTTP::Request.new :delete, "http://example.com"
res = redirect_response 301, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end
end

Expand Down Expand Up @@ -254,24 +254,24 @@ def redirect_response(status, location)
req = HTTP::Request.new :put, "http://example.com"
res = redirect_response 302, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end

it "raises StateError if original request was POST" do
req = HTTP::Request.new :post, "http://example.com"
res = redirect_response 302, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end

it "raises StateError if original request was DELETE" do
req = HTTP::Request.new :delete, "http://example.com"
res = redirect_response 302, "http://example.com/1"

expect { redirector.perform(req, res) { simple_response 200 } }
.to raise_error HTTP::StateError
expect { redirector.perform(req, res) { simple_response 200 } }.
to raise_error HTTP::StateError
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/http/response_spec.rb
Expand Up @@ -105,8 +105,8 @@
body = double :to_s => "foobar"
response = HTTP::Response.new(200, "1.1", headers, body)

expect(response.inspect)
.to eq '#<HTTP::Response/1.1 200 OK {"Content-Type"=>"text/plain"}>'
expect(response.inspect).
to eq '#<HTTP::Response/1.1 200 OK {"Content-Type"=>"text/plain"}>'
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/http_spec.rb
Expand Up @@ -185,8 +185,8 @@

it "sets Authorization header with proper BasicAuth value" do
client = HTTP.basic_auth :user => "foo", :pass => "bar"
expect(client.default_headers[:authorization])
.to match(%r{^Basic [A-Za-z0-9+/]+=*$})
expect(client.default_headers[:authorization]).
to match(%r{^Basic [A-Za-z0-9+/]+=*$})
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/support/http_handling_shared.rb
Expand Up @@ -82,8 +82,8 @@
end

it "errors if reading takes too long" do
expect { client.get("#{server.endpoint}/sleep").body.to_s }
.to raise_error(HTTP::TimeoutError, /Timed out/)
expect { client.get("#{server.endpoint}/sleep").body.to_s }.
to raise_error(HTTP::TimeoutError, /Timed out/)
end
end
end
Expand Down

4 comments on commit 110a338

@ixti
Copy link
Member

@ixti ixti commented on 110a338 Apr 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change introduced? :((

@sferik
Copy link
Contributor Author

@sferik sferik commented on 110a338 Apr 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you prefer it the other way?

@ixti
Copy link
Member

@ixti ixti commented on 110a338 Apr 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah :D It was actually trailing initially, but we switched to leading dot once ruby 1.8 support was dropped... IMO leading dot makes it a bit easier to read.

@ixti
Copy link
Member

@ixti ixti commented on 110a338 Apr 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I'm OK to stick with trailing dot instead of leading, if that makes things easier to others :D

Please sign in to comment.