Skip to content

Commit 11a1349

Browse files
committed
Fix more rubocop offenses
1 parent 1d05346 commit 11a1349

40 files changed

Lines changed: 286 additions & 97 deletions

.rubocop/metrics.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Metrics/ClassLength:
1616
- array
1717
- heredoc
1818
- method_call
19+
Exclude:
20+
- 'test/support/**/*.rb'
1921

2022
Metrics/MethodLength:
2123
CountAsOne:

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ group :development do
1212
end
1313

1414
group :test do
15-
gem "certificate_authority", "~> 1.0", require: false
1615
gem "logger"
1716

1817
gem "backports"

lib/http/base64.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
module HTTP
4+
# Strict Base64 encoding utilities
45
module Base64
56
module_function
67

lib/http/chainable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require "http/headers"
66

77
module HTTP
8+
# HTTP verb methods and client configuration DSL
89
module Chainable
910
include HTTP::Base64
1011

lib/http/chainable/helpers.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
module HTTP
4+
# HTTP verb methods and client configuration DSL
45
module Chainable
56
# Mapping of proxy argument positions to hash keys and expected types
67
PROXY_ARG_MAP = [

lib/http/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Client
1818
include Chainable
1919
include RequestBuilder
2020

21+
# Pattern matching HTTP or HTTPS URI schemes
2122
HTTP_OR_HTTPS_RE = %r{^https?://}i
2223

2324
# Initialize a new HTTP Client

lib/http/connection.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Connection
1313

1414
# Allowed values for CONNECTION header
1515
KEEP_ALIVE = "Keep-Alive"
16+
# Connection: close header value
1617
CLOSE = "close"
1718

1819
# Attempt to read this much data
@@ -113,10 +114,7 @@ def readpartial(size = BUFFER_SIZE)
113114
return chunk if chunk
114115

115116
eof = read_more(size) == :eof
116-
if eof && !@parser.finished? && body_framed?
117-
close
118-
raise ConnectionError, "response body ended prematurely"
119-
end
117+
check_premature_eof(eof)
120118

121119
finished = eof || @parser.finished?
122120
chunk = @parser.read(size)
@@ -221,6 +219,27 @@ def init_state(options)
221219
@parser = Response::Parser.new
222220
end
223221

222+
# Check for premature end-of-file and raise if detected
223+
#
224+
# @example
225+
# check_premature_eof(:eof)
226+
#
227+
# @return [void]
228+
# @api private
229+
def check_premature_eof(eof)
230+
return unless eof && !@parser.finished? && body_framed?
231+
232+
close
233+
raise ConnectionError, "response body ended prematurely"
234+
end
235+
236+
# Check if the response body has a known framing mechanism
237+
#
238+
# @example
239+
# body_framed?
240+
#
241+
# @return [Boolean]
242+
# @api private
224243
def body_framed?
225244
@parser.headers.include?(Headers::TRANSFER_ENCODING) ||
226245
@parser.headers.include?(Headers::CONTENT_LENGTH)

lib/http/content_type.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# frozen_string_literal: true
22

33
module HTTP
4+
# Parsed representation of a Content-Type header
45
class ContentType
6+
# Pattern for extracting MIME type from Content-Type header
57
MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)}
8+
# Pattern for extracting charset from Content-Type header
69
CHARSET_RE = /;\s*charset=([^;]+)/i
710

811
# MIME type of the content

lib/http/errors.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class ConnectionError < Error; end
99

1010
# Types of Connection errors
1111
class ResponseHeaderError < ConnectionError; end
12+
# Error raised when reading from a socket fails
1213
class SocketReadError < ConnectionError; end
14+
# Error raised when writing to a socket fails
1315
class SocketWriteError < ConnectionError; end
1416

1517
# Generic Request error

lib/http/feature.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
module HTTP
4+
# Base class for HTTP client features (middleware)
45
class Feature
56
# Wraps an HTTP request
67
#

0 commit comments

Comments
 (0)