protocol-http 0.19.0 → 0.22.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/protocol/http/body/buffered.rb +1 -0
- data/lib/protocol/http/body/{streamable.rb → completable.rb} +3 -3
- data/lib/protocol/http/body/readable.rb +15 -0
- data/lib/protocol/http/body/wrapper.rb +8 -0
- data/lib/protocol/http/cookie.rb +1 -1
- data/lib/protocol/http/header/authorization.rb +15 -13
- data/lib/protocol/http/header/etag.rb +0 -2
- data/lib/protocol/http/headers.rb +19 -15
- data/lib/protocol/http/methods.rb +1 -1
- data/lib/protocol/http/middleware/builder.rb +8 -6
- data/lib/protocol/http/reference.rb +1 -3
- data/lib/protocol/http/version.rb +1 -1
- metadata +10 -32
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -22
- data/Gemfile +0 -11
- data/README.md +0 -90
- data/protocol-http.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e91627263ea1f1b1c1744372ca276042bc0b901b3eef0fbb45cb79e49daae8
|
4
|
+
data.tar.gz: 4bbf0d84e477382c6a42551f25b73bd2adac17ea78f649490beba2b0f8462866
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c07409b15f91f5b3d3fcdaccaf2410fefd0fd513c1657dde0209c1aa4001a7c4ec15fc7843c4a403a089c37f0d2952c53300961e4bb1b8fd70b3a04876c31e6a
|
7
|
+
data.tar.gz: 3fb7f131549020cdfe0b79a0348fd14a8ee96f7acdbdd4f3faf9ce0781f9d48d21a006fbb2338764884795b822c7e6b0b10426a77a31d79f7110d721c1044f88
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright,
|
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
|
29
|
-
class
|
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`.
|
data/lib/protocol/http/cookie.rb
CHANGED
@@ -26,21 +26,23 @@ module Protocol
|
|
26
26
|
module HTTP
|
27
27
|
module Header
|
28
28
|
# Used for basic authorization.
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def encoded
|
39
|
-
"#{@username}:#{@password}"
|
29
|
+
#
|
30
|
+
# ~~~ ruby
|
31
|
+
# headers.add('authorization', Authorization.basic("my_username", "my_password"))
|
32
|
+
# ~~~
|
33
|
+
class Authorization < String
|
34
|
+
# Splits the header and
|
35
|
+
# @return [Tuple(String, String)]
|
36
|
+
def credentials
|
37
|
+
self.split(/\s+/, 2)
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
43
|
-
|
40
|
+
def self.basic(username, password)
|
41
|
+
encoded = "#{username}:#{password}"
|
42
|
+
|
43
|
+
self.new(
|
44
|
+
"Basic #{Base64.strict_encode64(encoded)}"
|
45
|
+
)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -28,6 +28,7 @@ require_relative 'header/cache_control'
|
|
28
28
|
require_relative 'header/etag'
|
29
29
|
require_relative 'header/etags'
|
30
30
|
require_relative 'header/vary'
|
31
|
+
require_relative 'header/authorization'
|
31
32
|
|
32
33
|
module Protocol
|
33
34
|
module HTTP
|
@@ -36,7 +37,7 @@ module Protocol
|
|
36
37
|
Split = Header::Split
|
37
38
|
Multiple = Header::Multiple
|
38
39
|
|
39
|
-
|
40
|
+
TRAILER = 'trailer'
|
40
41
|
|
41
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.
|
42
43
|
# @return [Headers] an instance of headers.
|
@@ -66,7 +67,7 @@ module Protocol
|
|
66
67
|
@fields = fields
|
67
68
|
@indexed = indexed
|
68
69
|
|
69
|
-
# Marks where
|
70
|
+
# Marks where trailer start in the @fields array.
|
70
71
|
@tail = nil
|
71
72
|
end
|
72
73
|
|
@@ -83,10 +84,10 @@ module Protocol
|
|
83
84
|
@tail = nil
|
84
85
|
end
|
85
86
|
|
86
|
-
# Flatten
|
87
|
+
# Flatten trailer into the headers.
|
87
88
|
def flatten!
|
88
89
|
if @tail
|
89
|
-
self.delete(
|
90
|
+
self.delete(TRAILER)
|
90
91
|
@tail = nil
|
91
92
|
end
|
92
93
|
|
@@ -100,27 +101,27 @@ module Protocol
|
|
100
101
|
# An array of `[key, value]` pairs.
|
101
102
|
attr :fields
|
102
103
|
|
103
|
-
# @return the
|
104
|
-
def
|
104
|
+
# @return the trailer if there are any.
|
105
|
+
def trailer?
|
105
106
|
@tail != nil
|
106
107
|
end
|
107
108
|
|
108
|
-
# Record the current headers, and prepare to receive
|
109
|
-
def
|
110
|
-
return nil unless self.include?(
|
109
|
+
# Record the current headers, and prepare to receive trailer.
|
110
|
+
def trailer!(&block)
|
111
|
+
return nil unless self.include?(TRAILER)
|
111
112
|
|
112
113
|
@tail ||= @fields.size
|
113
114
|
|
114
|
-
return to_enum(:
|
115
|
+
return to_enum(:trailer!) unless block_given?
|
115
116
|
|
116
117
|
if @tail
|
117
118
|
@fields.drop(@tail).each(&block)
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
121
|
-
# Enumerate all
|
122
|
-
def
|
123
|
-
return to_enum(:
|
122
|
+
# Enumerate all headers in the trailer, if there are any.
|
123
|
+
def trailer(&block)
|
124
|
+
return to_enum(:trailer) unless block_given?
|
124
125
|
|
125
126
|
if @tail
|
126
127
|
@fields.drop(@tail).each(&block)
|
@@ -170,6 +171,7 @@ module Protocol
|
|
170
171
|
end
|
171
172
|
|
172
173
|
# Add the specified header key value pair.
|
174
|
+
#
|
173
175
|
# @param key [String] the header key.
|
174
176
|
# @param value [String] the header value to assign.
|
175
177
|
def add(key, value)
|
@@ -216,8 +218,6 @@ module Protocol
|
|
216
218
|
'user-agent' => false,
|
217
219
|
'referer' => false,
|
218
220
|
'host' => false,
|
219
|
-
'authorization' => false,
|
220
|
-
'proxy-authorization' => false,
|
221
221
|
'if-modified-since' => false,
|
222
222
|
'if-unmodified-since' => false,
|
223
223
|
'from' => false,
|
@@ -233,6 +233,10 @@ module Protocol
|
|
233
233
|
'via' => Split,
|
234
234
|
'x-forwarded-for' => Split,
|
235
235
|
|
236
|
+
# Authorization headers:
|
237
|
+
'authorization' => Header::Authorization,
|
238
|
+
'proxy-authorization' => Header::Authorization,
|
239
|
+
|
236
240
|
# Cache validations:
|
237
241
|
'etag' => Header::ETag,
|
238
242
|
'if-match' => Header::ETags,
|
@@ -53,7 +53,7 @@ module Protocol
|
|
53
53
|
self.each do |name, value|
|
54
54
|
define_method(name.downcase) do |location, headers = nil, body = nil|
|
55
55
|
self.call(
|
56
|
-
Request[value, location.
|
56
|
+
Request[value, location.to_s, Headers[headers], body]
|
57
57
|
)
|
58
58
|
end
|
59
59
|
end
|
@@ -35,15 +35,13 @@ module Protocol
|
|
35
35
|
end
|
36
36
|
|
37
37
|
class Builder
|
38
|
-
def initialize(default_app = NotFound
|
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, *
|
46
|
-
@use << proc {|app| middleware.new(app, *
|
43
|
+
def use(middleware, *arguments, **options, &block)
|
44
|
+
@use << proc {|app| middleware.new(app, *arguments, **options, &block)}
|
47
45
|
end
|
48
46
|
|
49
47
|
def run(app)
|
@@ -56,7 +54,11 @@ module Protocol
|
|
56
54
|
end
|
57
55
|
|
58
56
|
def self.build(&block)
|
59
|
-
Builder.new
|
57
|
+
builder = Builder.new
|
58
|
+
|
59
|
+
builder.instance_eval(&block)
|
60
|
+
|
61
|
+
return builder.to_app
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -110,12 +110,10 @@ module Protocol
|
|
110
110
|
return buffer
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
113
|
+
def to_s
|
114
114
|
append(String.new)
|
115
115
|
end
|
116
116
|
|
117
|
-
alias to_s to_str
|
118
|
-
|
119
117
|
# Merges two references as specified by RFC2396, similar to `URI.join`.
|
120
118
|
def + other
|
121
119
|
other = self.class[other]
|
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.
|
4
|
+
version: 0.22.1
|
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:
|
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:
|
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.
|
138
|
-
signing_key:
|
115
|
+
rubygems_version: 3.2.15
|
116
|
+
signing_key:
|
139
117
|
specification_version: 4
|
140
118
|
summary: Provides abstractions to handle HTTP protocols.
|
141
119
|
test_files: []
|
data/.editorconfig
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
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
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.
|
data/protocol-http.gemspec
DELETED
@@ -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
|