protocol-http 0.22.4 → 0.22.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5ce664c282254446c2a0630171f738e1f2649f79610357c6516278bb1daa8b8
4
- data.tar.gz: 6e279c9da31e55d441e2bdc95bd1802ac89688e03d80a6f7a6bfe1d6b3b505ee
3
+ metadata.gz: 3941486c86fe210a4ba79c2c77c73bfa3de8cd7cfbfe892c4b6d0b48699260c2
4
+ data.tar.gz: afd65fb56ed88d184249ab56d87271f6926d398e8460135315e571b1848416a5
5
5
  SHA512:
6
- metadata.gz: febde12794a4c38af66b3578af6ffeb5ffdbf8bf606b9c7c413e6b4f4e2cd65452100fbe8ec33794be2f5cb044c4db1bb151763ff7a3f30bda7b9e766ee3738d
7
- data.tar.gz: 96ce0f77a34495f5ee10c4b00099db58be7fbaceaef65249ed5e3abaa931cc7f7bb6df048a901923fc7113624fb7bd21becae6263e28ee3000cc617fc662b3ae
6
+ metadata.gz: 10e885a3c13ec3a380c774b62e4e5fdd1a0a378766eca8650733909917ab964ccb85b39aa39105d522d8efd93b917a546029c1d70260fef4ba719c984f055926
7
+ data.tar.gz: b67aa62dc2d4f5e5c3e6d97cd4f40044de8a7b02dac0343aa796dcdf936171f3ec097819d3e70ec4af76ec493496c3507b6ec62302571b76b5ac359e9d015641
@@ -72,7 +72,7 @@ module Protocol
72
72
  stream.write(chunk)
73
73
  end
74
74
  ensure
75
- stream.close($!)
75
+ stream.close
76
76
  end
77
77
 
78
78
  # Read all remaining chunks into a buffered body and close the underlying input.
@@ -76,6 +76,11 @@ module Protocol
76
76
  @buffer ||= read_next
77
77
  chunk = nil
78
78
 
79
+ unless @buffer
80
+ buffer&.clear
81
+ return
82
+ end
83
+
79
84
  if @buffer.bytesize > length
80
85
  chunk = @buffer.byteslice(0, length)
81
86
  @buffer = @buffer.byteslice(length, @buffer.bytesize)
@@ -94,7 +99,12 @@ module Protocol
94
99
  end
95
100
 
96
101
  def write(buffer)
97
- @output.write(buffer)
102
+ if @output
103
+ @output.write(buffer)
104
+ return buffer.bytesize
105
+ else
106
+ raise IOError, "Stream is not writable, output has been closed!"
107
+ end
98
108
  end
99
109
 
100
110
  alias write_nonblock write
@@ -104,17 +114,21 @@ module Protocol
104
114
 
105
115
  def close_read
106
116
  @input&.close
117
+ @input = nil
107
118
  end
108
119
 
109
120
  # close must never be called on the input stream. huh?
110
121
  def close_write
111
122
  @output&.close
123
+ @output = nil
112
124
  end
113
125
 
114
126
  # Close the input and output bodies.
115
127
  def close
116
128
  self.close_read
117
129
  self.close_write
130
+
131
+ return nil
118
132
  ensure
119
133
  @closed = true
120
134
  end
@@ -132,11 +146,11 @@ module Protocol
132
146
  private
133
147
 
134
148
  def read_next
135
- if chunk = @input&.read
136
- return chunk
149
+ if @input
150
+ return @input.read
137
151
  else
138
152
  @input = nil
139
- return nil
153
+ raise IOError, "Stream is not readable, input has been closed!"
140
154
  end
141
155
  end
142
156
  end
@@ -72,8 +72,8 @@ module Protocol
72
72
  directives = self.parse_directives(directives)
73
73
 
74
74
  self.new(
75
- URI.decode(key),
76
- URI.decode(value),
75
+ URL.unescape(key),
76
+ URL.unescape(value),
77
77
  directives,
78
78
  )
79
79
  end
@@ -101,22 +101,27 @@ module Protocol
101
101
  # An array of `[key, value]` pairs.
102
102
  attr :fields
103
103
 
104
- # @return the trailer if there are any.
104
+ # @returns Whether there are any trailers.
105
105
  def trailer?
106
106
  @tail != nil
107
107
  end
108
108
 
109
- # Record the current headers, and prepare to receive trailer.
109
+ # Record the current headers, and prepare to add trailers.
110
+ #
111
+ # This method is typically used after headers are sent to capture any
112
+ # additional headers which should then be sent as trailers.
113
+ #
114
+ # A sender that intends to generate one or more trailer fields in a
115
+ # message should generate a trailer header field in the header section of
116
+ # that message to indicate which fields might be present in the trailers.
117
+ #
118
+ # @parameter names [Array] The trailer header names which will be added later.
119
+ # @yields block {|name, value| ...} The trailer headers if any.
120
+ # @returns An enumerator which is suitable for iterating over trailers.
110
121
  def trailer!(&block)
111
- return nil unless self.include?(TRAILER)
112
-
113
122
  @tail ||= @fields.size
114
123
 
115
- return to_enum(:trailer!) unless block_given?
116
-
117
- if @tail
118
- @fields.drop(@tail).each(&block)
119
- end
124
+ return trailer(&block)
120
125
  end
121
126
 
122
127
  # Enumerate all headers in the trailer, if there are any.
@@ -23,13 +23,14 @@
23
23
  module Protocol
24
24
  module HTTP
25
25
  module URL
26
- # Escapes a generic string, using percent encoding.
26
+ # Escapes a string using percent encoding.
27
27
  def self.escape(string, encoding = string.encoding)
28
28
  string.b.gsub(/([^a-zA-Z0-9_.\-]+)/) do |m|
29
29
  '%' + m.unpack('H2' * m.bytesize).join('%').upcase
30
30
  end.force_encoding(encoding)
31
31
  end
32
32
 
33
+ # Unescapes a percent encoded string.
33
34
  def self.unescape(string, encoding = string.encoding)
34
35
  string.b.gsub(/%(\h\h)/) do |hex|
35
36
  Integer(hex, 16).chr
@@ -39,7 +40,7 @@ module Protocol
39
40
  # According to https://tools.ietf.org/html/rfc3986#section-3.3, we escape non-pchar.
40
41
  NON_PCHAR = /([^a-zA-Z0-9_\-\.~!$&'()*+,;=:@\/]+)/.freeze
41
42
 
42
- # Escapes a path
43
+ # Escapes non-path characters using percent encoding.
43
44
  def self.escape_path(path)
44
45
  encoding = path.encoding
45
46
  path.b.gsub(NON_PCHAR) do |m|
@@ -47,7 +48,7 @@ module Protocol
47
48
  end.force_encoding(encoding)
48
49
  end
49
50
 
50
- # Encodes a hash or array into a query string
51
+ # Encodes a hash or array into a query string.
51
52
  def self.encode(value, prefix = nil)
52
53
  case value
53
54
  when Array
@@ -67,9 +68,12 @@ module Protocol
67
68
  end
68
69
  end
69
70
 
71
+ # Scan a string for URL-encoded key/value pairs.
72
+ # @yields {|key, value| ...}
73
+ # @parameter key [String] The unescaped key.
74
+ # @parameter value [String] The unescaped key.
70
75
  def self.scan(string)
71
- # TODO Ruby 2.6 doesn't require `.each`
72
- string.split('&').each do |assignment|
76
+ string.split('&') do |assignment|
73
77
  key, value = assignment.split('=', 2)
74
78
 
75
79
  yield unescape(key), unescape(value)
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module HTTP
25
- VERSION = "0.22.4"
25
+ VERSION = "0.22.7"
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.4
4
+ version: 0.22.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-22 00:00:00.000000000 Z
11
+ date: 2022-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubygems_version: 3.1.6
115
+ rubygems_version: 3.3.7
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Provides abstractions to handle HTTP protocols.