protocol-http 0.20.0 → 0.22.2

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: 155e5d73168b2ff9c429d2677150ae8a30e87ee8fb25a582ac30671f8e015ad2
4
- data.tar.gz: c3ae63c177fc673100717c5f2c81bbde8e8a3192de7d010e903593f82d68f2e4
3
+ metadata.gz: 891c8ccab1e36efa1e8aaec311b0c451e5ecc8e3cd1a858ec01d2cb5728d14f6
4
+ data.tar.gz: 9189058a0f89b42ef4dd24e307a00965129a2fbfa667d613515bea0c51b43c91
5
5
  SHA512:
6
- metadata.gz: '08db581bcc0840a176039b99f8a9bb31c9db02fb9476ef318c26db8b37d73626754d929efd3cddc70446c5dbecb1708d8bb0347c873a0328b79fe6a0faf6fcdb'
7
- data.tar.gz: 64a7ff013c2e459c594f9c87dcd19d0056d9492136b9c97121d411ebafd74cfe47feacc76842863af7e40d9c38a877ef143e6d0253cf052a63648091f829f8d0
6
+ metadata.gz: 67b637ea3885e241224c26f2a400164bea13cd40bc2ae3517506648315fb4e6d76d91adae87b55119c26b3d85bf299fa62996ab8a19edf5cc04f781a91ef073f
7
+ data.tar.gz: 05c02502dc387d9f07a358065d75ba2e659e4363f6c15a71b3acdff80be130ca00a445ce803e9f07092ccdd0cca765888cd4331b6be125ec2dd960c1449741e9
@@ -56,6 +56,7 @@ module Protocol
56
56
  @length = length
57
57
 
58
58
  @index = 0
59
+ @digest = nil
59
60
  end
60
61
 
61
62
  attr :chunks
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the "Software"), to deal
@@ -25,8 +25,8 @@ require_relative 'wrapper'
25
25
  module Protocol
26
26
  module HTTP
27
27
  module Body
28
- # Invokes a callback once the body has finished reading.
29
- class Streamable < Wrapper
28
+ # Invokes a callback once the body has completed, either successfully or due to an error.
29
+ class Completable < Wrapper
30
30
  def self.wrap(message, &block)
31
31
  if body = message&.body and !body.empty?
32
32
  message.body = self.new(message.body, block)
@@ -60,6 +60,21 @@ module Protocol
60
60
  nil
61
61
  end
62
62
 
63
+ # Should the internal mechanism prefer to use {call}?
64
+ # @returns [Boolean]
65
+ def stream?
66
+ false
67
+ end
68
+
69
+ # Write the body to the given stream.
70
+ def call(stream)
71
+ while chunk = self.read
72
+ stream.write(chunk)
73
+ end
74
+ ensure
75
+ stream.close($!)
76
+ end
77
+
63
78
  # Read all remaining chunks into a buffered body and close the underlying input.
64
79
  def finish
65
80
  # Internally, this invokes `self.each` which then invokes `self.close`.
@@ -71,6 +71,14 @@ module Protocol
71
71
  def inspect
72
72
  @body.inspect
73
73
  end
74
+
75
+ def stream?
76
+ @body.stream?
77
+ end
78
+
79
+ def call(stream)
80
+ @body.call(stream)
81
+ end
74
82
  end
75
83
  end
76
84
  end
@@ -37,7 +37,7 @@ module Protocol
37
37
  Split = Header::Split
38
38
  Multiple = Header::Multiple
39
39
 
40
- TRAILERS = 'trailers'
40
+ TRAILER = 'trailer'
41
41
 
42
42
  # Construct an instance from a headers Array or Hash. No-op if already an instance of `Headers`. If the underlying array is frozen, it will be duped.
43
43
  # @return [Headers] an instance of headers.
@@ -67,7 +67,7 @@ module Protocol
67
67
  @fields = fields
68
68
  @indexed = indexed
69
69
 
70
- # Marks where trailers start in the @fields array.
70
+ # Marks where trailer start in the @fields array.
71
71
  @tail = nil
72
72
  end
73
73
 
@@ -84,10 +84,10 @@ module Protocol
84
84
  @tail = nil
85
85
  end
86
86
 
87
- # Flatten trailers into the headers.
87
+ # Flatten trailer into the headers.
88
88
  def flatten!
89
89
  if @tail
90
- self.delete(TRAILERS)
90
+ self.delete(TRAILER)
91
91
  @tail = nil
92
92
  end
93
93
 
@@ -101,27 +101,27 @@ module Protocol
101
101
  # An array of `[key, value]` pairs.
102
102
  attr :fields
103
103
 
104
- # @return the trailers if there are any.
105
- def trailers?
104
+ # @return the trailer if there are any.
105
+ def trailer?
106
106
  @tail != nil
107
107
  end
108
108
 
109
- # Record the current headers, and prepare to receive trailers.
110
- def trailers!(&block)
111
- return nil unless self.include?(TRAILERS)
109
+ # Record the current headers, and prepare to receive trailer.
110
+ def trailer!(&block)
111
+ return nil unless self.include?(TRAILER)
112
112
 
113
113
  @tail ||= @fields.size
114
114
 
115
- return to_enum(:trailers!) unless block_given?
115
+ return to_enum(:trailer!) unless block_given?
116
116
 
117
117
  if @tail
118
118
  @fields.drop(@tail).each(&block)
119
119
  end
120
120
  end
121
121
 
122
- # Enumerate all trailers, if there are any.
123
- def trailers(&block)
124
- return to_enum(:trailers) unless block_given?
122
+ # Enumerate all headers in the trailer, if there are any.
123
+ def trailer(&block)
124
+ return to_enum(:trailer) unless block_given?
125
125
 
126
126
  if @tail
127
127
  @fields.drop(@tail).each(&block)
@@ -35,17 +35,17 @@ module Protocol
35
35
  end
36
36
 
37
37
  class Builder
38
- def initialize(default_app = NotFound, &block)
38
+ def initialize(default_app = NotFound)
39
39
  @use = []
40
40
  @app = default_app
41
-
42
- instance_eval(&block) if block_given?
43
41
  end
44
42
 
45
- def use(middleware, *args, &block)
46
- @use << proc {|app| middleware.new(app, *args, &block)}
43
+ def use(middleware, *arguments, &block)
44
+ @use << proc {|app| middleware.new(app, *arguments, &block)}
47
45
  end
48
46
 
47
+ ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
48
+
49
49
  def run(app)
50
50
  @app = app
51
51
  end
@@ -56,7 +56,11 @@ module Protocol
56
56
  end
57
57
 
58
58
  def self.build(&block)
59
- Builder.new(&block).to_app
59
+ builder = Builder.new
60
+
61
+ builder.instance_eval(&block)
62
+
63
+ return builder.to_app
60
64
  end
61
65
  end
62
66
  end
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module HTTP
25
- VERSION = "0.20.0"
25
+ VERSION = "0.22.2"
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.22.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2021-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: covered
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +25,7 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: bake-bundler
28
+ name: covered
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -66,22 +52,16 @@ dependencies:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
- description:
55
+ description:
70
56
  email:
71
- - samuel.williams@oriontransfer.co.nz
72
57
  executables: []
73
58
  extensions: []
74
59
  extra_rdoc_files: []
75
60
  files:
76
- - ".editorconfig"
77
- - ".gitignore"
78
- - ".rspec"
79
- - ".travis.yml"
80
- - Gemfile
81
- - README.md
82
61
  - lib/protocol/http.rb
83
62
  - lib/protocol/http/accept_encoding.rb
84
63
  - lib/protocol/http/body/buffered.rb
64
+ - lib/protocol/http/body/completable.rb
85
65
  - lib/protocol/http/body/deflate.rb
86
66
  - lib/protocol/http/body/digestable.rb
87
67
  - lib/protocol/http/body/file.rb
@@ -91,7 +71,6 @@ files:
91
71
  - lib/protocol/http/body/reader.rb
92
72
  - lib/protocol/http/body/rewindable.rb
93
73
  - lib/protocol/http/body/stream.rb
94
- - lib/protocol/http/body/streamable.rb
95
74
  - lib/protocol/http/body/wrapper.rb
96
75
  - lib/protocol/http/content_encoding.rb
97
76
  - lib/protocol/http/cookie.rb
@@ -114,18 +93,17 @@ files:
114
93
  - lib/protocol/http/response.rb
115
94
  - lib/protocol/http/url.rb
116
95
  - lib/protocol/http/version.rb
117
- - protocol-http.gemspec
118
96
  homepage: https://github.com/socketry/protocol-http
119
97
  licenses:
120
98
  - MIT
121
99
  metadata: {}
122
- post_install_message:
100
+ post_install_message:
123
101
  rdoc_options: []
124
102
  require_paths:
125
103
  - lib
126
104
  required_ruby_version: !ruby/object:Gem::Requirement
127
105
  requirements:
128
- - - "~>"
106
+ - - ">="
129
107
  - !ruby/object:Gem::Version
130
108
  version: '2.5'
131
109
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -134,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
112
  - !ruby/object:Gem::Version
135
113
  version: '0'
136
114
  requirements: []
137
- rubygems_version: 3.1.2
138
- signing_key:
115
+ rubygems_version: 3.0.3
116
+ signing_key:
139
117
  specification_version: 4
140
118
  summary: Provides abstractions to handle HTTP protocols.
141
119
  test_files: []
data/.editorconfig DELETED
@@ -1,6 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = tab
5
- indent_size = 2
6
-
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
- Gemfile.lock
13
- .covered.db
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --warnings
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- script: bundle exec rspec
6
-
7
- matrix:
8
- include:
9
- - rvm: 2.5
10
- - rvm: 2.6
11
- - rvm: 2.7
12
- - rvm: 2.6
13
- env: COVERAGE=PartialSummary,Coveralls
14
- - rvm: 2.7
15
- - rvm: truffleruby
16
- - rvm: jruby-head
17
- env: JRUBY_OPTS="--debug -X+O"
18
- - rvm: ruby-head
19
- allow_failures:
20
- - rvm: truffleruby
21
- - rvm: ruby-head
22
- - rvm: jruby-head
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in protocol-http.gemspec
6
- gemspec
7
-
8
- group :test do
9
- gem 'async-io'
10
- gem 'async-rspec'
11
- end
data/README.md DELETED
@@ -1,90 +0,0 @@
1
- # Protocol::HTTP
2
-
3
- Provides abstractions for working with the HTTP protocol.
4
-
5
- [![Build Status](https://travis-ci.com/socketry/protocol-http.svg?branch=master)](http://travis-ci.com/socketry/protocol-http)
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'protocol-http'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install protocol-http
22
-
23
- ## Usage
24
-
25
- ### Headers
26
-
27
- ```ruby
28
- require 'protocol/http/headers'
29
-
30
- headers = Protocol::HTTP::Headers.new
31
-
32
- headers['Content-Type'] = "image/jpeg"
33
-
34
- headers['content-type']
35
- # => "image/jpeg"
36
- ```
37
-
38
- ### Reference
39
-
40
- ```ruby
41
- require 'protocol/http/reference'
42
-
43
- reference = Protocol::HTTP::Reference.new("/search", q: 'kittens')
44
-
45
- reference.to_s
46
- # => "/search?q=kittens"
47
- ```
48
-
49
- ### URL
50
-
51
- ```ruby
52
- require 'protocol/http/url'
53
-
54
- reference = Protocol::HTTP::Reference.parse("/search?q=kittens")
55
-
56
- parameters = Protocol::HTTP::URL.decode(reference.query_string)
57
- # => {"q"=>"kittens"}
58
- ```
59
-
60
- ## Contributing
61
-
62
- 1. Fork it
63
- 2. Create your feature branch (`git checkout -b my-new-feature`)
64
- 3. Commit your changes (`git commit -am 'Add some feature'`)
65
- 4. Push to the branch (`git push origin my-new-feature`)
66
- 5. Create new Pull Request
67
-
68
- ## License
69
-
70
- Released under the MIT license.
71
-
72
- Copyright, 2019, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
73
-
74
- Permission is hereby granted, free of charge, to any person obtaining a copy
75
- of this software and associated documentation files (the "Software"), to deal
76
- in the Software without restriction, including without limitation the rights
77
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78
- copies of the Software, and to permit persons to whom the Software is
79
- furnished to do so, subject to the following conditions:
80
-
81
- The above copyright notice and this permission notice shall be included in
82
- all copies or substantial portions of the Software.
83
-
84
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
87
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
89
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
90
- THE SOFTWARE.
@@ -1,26 +0,0 @@
1
-
2
- require_relative "lib/protocol/http/version"
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "protocol-http"
6
- spec.version = Protocol::HTTP::VERSION
7
- spec.authors = ["Samuel Williams"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
-
10
- spec.summary = "Provides abstractions to handle HTTP protocols."
11
- spec.homepage = "https://github.com/socketry/protocol-http"
12
- spec.license = "MIT"
13
-
14
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
- f.match(%r{^(test|spec|features)/})
16
- end
17
-
18
- spec.required_ruby_version = '~> 2.5'
19
-
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "covered"
23
- spec.add_development_dependency "bundler"
24
- spec.add_development_dependency "bake-bundler"
25
- spec.add_development_dependency "rspec"
26
- end