protocol-http 0.23.1 → 0.23.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee01a36222c1035b06230948ac4afd7d5f8894416c7db3f46f3d2ff3735c84c4
4
- data.tar.gz: 809f145dc27bdd25d8d39467b7583a1778c21e0f91d93e5bc5e697324b1e9d29
3
+ metadata.gz: 0a90ddbbf77b6838a596c01ff6bc77d7f67867eb91cc3560d92da5458a011af9
4
+ data.tar.gz: 803a2218c2d60270c8eca75f49d1063a1b61fd45d66a0313d6e20a0abf2d0587
5
5
  SHA512:
6
- metadata.gz: 4188214bf6e420e204a689484d2469e0d577270541a803bf366ceafa5fd8edcd652649a59616ce1b965744017785e348ea4a8ecdb396324af1c0815c423715da
7
- data.tar.gz: 3450d3826c351d7e4da8a94bc4f6d9dac81fd8386a7c2eac4753077da0055344e924d7283090cc1f443261060dec0c0a1d5803f851e1690df3dc1405552a05b6
6
+ metadata.gz: 36f23a497f933e91cf8ca08e367faeaba6539fdafc86587aca27d0ad7e4f2c2d7fe4f3224f9f7509f07e5fdabf733a72c875a7cb2ba29d507b3dcba5b1af6777
7
+ data.tar.gz: 056d805e7795929d8af1609e490bb4ff86b7c9e083c585ed08aee68ea810ba9fddcc3beceb1ec0102e245cbf6f2a2712c03bbf8d83a153b0eac4ce369ef4f54b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -56,7 +56,6 @@ module Protocol
56
56
  @length = length
57
57
 
58
58
  @index = 0
59
- @digest = nil
60
59
  end
61
60
 
62
61
  attr :chunks
@@ -87,7 +86,6 @@ module Protocol
87
86
  end
88
87
 
89
88
  def write(chunk)
90
- @digest&.update(chunk)
91
89
  @chunks << chunk
92
90
  end
93
91
 
@@ -41,100 +41,107 @@ module Protocol
41
41
  attr :input
42
42
  attr :output
43
43
 
44
- # rack.hijack_io must respond to:
45
- # read, write, read_nonblock, write_nonblock, flush, close, close_read, close_write, closed?
46
-
47
- # read behaves like IO#read. Its signature is read([length, [buffer]]). If given, length must be a non-negative Integer (>= 0) or nil, and buffer must be a String and may not be nil. If length is given and not nil, then this method reads at most length bytes from the input stream. If length is not given or nil, then this method reads all data until EOF. When EOF is reached, this method returns nil if length is given and not nil, or “” if length is not given or is nil. If buffer is given, then the read data will be placed into buffer instead of a newly created String object.
48
- # @param length [Integer] the amount of data to read
49
- # @param buffer [String] the buffer which will receive the data
50
- # @return a buffer containing the data
51
- def read(length = nil, buffer = nil)
52
- return '' if length == 0
53
-
54
- buffer ||= Async::IO::Buffer.new
55
-
56
- # Take any previously buffered data and replace it into the given buffer.
57
- if @buffer
58
- buffer.replace(@buffer)
59
- @buffer = nil
60
- end
44
+ # This provides a read-only interface for data, which is surprisingly tricky to implement correctly.
45
+ module Reader
46
+ # rack.hijack_io must respond to:
47
+ # read, write, read_nonblock, write_nonblock, flush, close, close_read, close_write, closed?
61
48
 
62
- if length
63
- while buffer.bytesize < length and chunk = read_next
64
- buffer << chunk
65
- end
49
+ # read behaves like IO#read. Its signature is read([length, [buffer]]). If given, length must be a non-negative Integer (>= 0) or nil, and buffer must be a String and may not be nil. If length is given and not nil, then this method reads at most length bytes from the input stream. If length is not given or nil, then this method reads all data until EOF. When EOF is reached, this method returns nil if length is given and not nil, or “” if length is not given or is nil. If buffer is given, then the read data will be placed into buffer instead of a newly created String object.
50
+ # @param length [Integer] the amount of data to read
51
+ # @param buffer [String] the buffer which will receive the data
52
+ # @return a buffer containing the data
53
+ def read(length = nil, buffer = nil)
54
+ return '' if length == 0
66
55
 
67
- # This ensures the subsequent `slice!` works correctly.
68
- buffer.force_encoding(Encoding::BINARY)
56
+ buffer ||= Async::IO::Buffer.new
69
57
 
70
- # This will be at least one copy:
71
- @buffer = buffer.byteslice(length, buffer.bytesize)
72
-
73
- # This should be zero-copy:
74
- buffer.slice!(length)
75
-
76
- if buffer.empty?
77
- return nil
58
+ # Take any previously buffered data and replace it into the given buffer.
59
+ if @buffer
60
+ buffer.replace(@buffer)
61
+ @buffer = nil
78
62
  else
79
- return buffer
80
- end
81
- else
82
- while chunk = read_next
83
- buffer << chunk
63
+ buffer.clear
84
64
  end
85
65
 
86
- return buffer
87
- end
88
- end
89
-
90
- # Read at most `length` bytes from the stream. Will avoid reading from the underlying stream if possible.
91
- def read_partial(length = nil)
92
- if @buffer
93
- buffer = @buffer
94
- @buffer = nil
95
- else
96
- buffer = read_next
97
- end
98
-
99
- if buffer and length
100
- if buffer.bytesize > length
66
+ if length
67
+ while buffer.bytesize < length and chunk = read_next
68
+ buffer << chunk
69
+ end
70
+
101
71
  # This ensures the subsequent `slice!` works correctly.
102
72
  buffer.force_encoding(Encoding::BINARY)
103
73
 
74
+ # This will be at least one copy:
104
75
  @buffer = buffer.byteslice(length, buffer.bytesize)
105
- buffer.slice!(length)
76
+
77
+ # This should be zero-copy:
78
+ buffer.slice!(length, buffer.bytesize)
79
+
80
+ if buffer.empty?
81
+ return nil
82
+ else
83
+ return buffer
84
+ end
85
+ else
86
+ while chunk = read_next
87
+ buffer << chunk
88
+ end
89
+
90
+ return buffer
106
91
  end
107
92
  end
108
93
 
109
- return buffer
110
- end
111
-
112
- def read_nonblock(length, buffer = nil)
113
- @buffer ||= read_next
114
- chunk = nil
115
-
116
- unless @buffer
117
- buffer&.clear
118
- return
119
- end
120
-
121
- if @buffer.bytesize > length
122
- chunk = @buffer.byteslice(0, length)
123
- @buffer = @buffer.byteslice(length, @buffer.bytesize)
124
- else
125
- chunk = @buffer
126
- @buffer = nil
94
+ # Read at most `length` bytes from the stream. Will avoid reading from the underlying stream if possible.
95
+ def read_partial(length = nil)
96
+ if @buffer
97
+ buffer = @buffer
98
+ @buffer = nil
99
+ else
100
+ buffer = read_next
101
+ end
102
+
103
+ if buffer and length
104
+ if buffer.bytesize > length
105
+ # This ensures the subsequent `slice!` works correctly.
106
+ buffer.force_encoding(Encoding::BINARY)
107
+
108
+ @buffer = buffer.byteslice(length, buffer.bytesize)
109
+ buffer.slice!(length, buffer.bytesize)
110
+ end
111
+ end
112
+
113
+ return buffer
127
114
  end
128
115
 
129
- if buffer
130
- buffer.replace(chunk)
131
- else
132
- buffer = chunk
116
+ def read_nonblock(length, buffer = nil)
117
+ @buffer ||= read_next
118
+ chunk = nil
119
+
120
+ unless @buffer
121
+ buffer&.clear
122
+ return
123
+ end
124
+
125
+ if @buffer.bytesize > length
126
+ chunk = @buffer.byteslice(0, length)
127
+ @buffer = @buffer.byteslice(length, @buffer.bytesize)
128
+ else
129
+ chunk = @buffer
130
+ @buffer = nil
131
+ end
132
+
133
+ if buffer
134
+ buffer.replace(chunk)
135
+ else
136
+ buffer = chunk
137
+ end
138
+
139
+ return buffer
133
140
  end
134
-
135
- return buffer
136
141
  end
137
142
 
143
+ include Reader
144
+
138
145
  def write(buffer)
139
146
  if @output
140
147
  @output.write(buffer)
@@ -340,11 +340,11 @@ module Protocol
340
340
  return self
341
341
  end
342
342
 
343
- # @yield [String, String] header key (lower case) and value (as string).
343
+ # @yields [String, String] header key (lower case string) and value (as string).
344
344
  def each(&block)
345
345
  @all.each do |headers|
346
346
  headers.each do |key, value|
347
- yield key.downcase, value.to_s
347
+ yield key.to_s.downcase, value.to_s
348
348
  end
349
349
  end
350
350
  end
@@ -39,13 +39,28 @@ module Protocol
39
39
  @protocol = protocol
40
40
  end
41
41
 
42
+ # The request scheme, usually one of "http" or "https".
42
43
  attr_accessor :scheme
44
+
45
+ # The request authority, usually a hostname and port number.
43
46
  attr_accessor :authority
47
+
48
+ # The request method, usually one of "GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT" or "OPTIONS".
44
49
  attr_accessor :method
50
+
51
+ # The request path, usually a path and query string.
45
52
  attr_accessor :path
53
+
54
+ # The request version, usually "http/1.0", "http/1.1", "h2", or "h3".
46
55
  attr_accessor :version
56
+
57
+ # The request headers, contains metadata associated with the request such as the user agent, accept (content type), accept-language, etc.
47
58
  attr_accessor :headers
59
+
60
+ # The request body, an instance of Protocol::HTTP::Body::Readable or similar.
48
61
  attr_accessor :body
62
+
63
+ # The request protocol, usually empty, but occasionally "websocket" or "webtransport", can be either single value `String` or multi-value `Array` of `String` instances. In HTTP/1, it is used to request a connection upgrade, and in HTTP/2 it is used to indicate a specfic protocol for the stream.
49
64
  attr_accessor :protocol
50
65
 
51
66
  # Send the request to the given connection.
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module HTTP
25
- VERSION = "0.23.1"
25
+ VERSION = "0.23.4"
26
26
  end
27
27
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.1
4
+ version: 0.23.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -41,7 +41,7 @@ cert_chain:
41
41
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
42
42
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
43
43
  -----END CERTIFICATE-----
44
- date: 2022-08-07 00:00:00.000000000 Z
44
+ date: 2022-08-15 00:00:00.000000000 Z
45
45
  dependencies:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bundler
metadata.gz.sig CHANGED
Binary file