protocol-http 0.24.2 → 0.24.4
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/conduct.md +133 -0
- data/lib/protocol/http/body/readable.rb +9 -4
- data/lib/protocol/http/body/stream.rb +6 -2
- data/lib/protocol/http/methods.rb +43 -7
- data/lib/protocol/http/middleware/builder.rb +2 -4
- data/lib/protocol/http/middleware.rb +10 -0
- data/lib/protocol/http/version.rb +1 -1
- data/license.md +2 -1
- data/readme.md +16 -5
- data.tar.gz.sig +0 -0
- metadata +5 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d38d0dafbaffa0935bd4ab90a6148cfb23f28d9c127c614f6bcd2cc7a1eca3
|
4
|
+
data.tar.gz: 348aa54b4f61f7af9d7090f96c8539f34a19de1a53f183ece45f303fe3a85008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 554ffff4bce62770aca71d6e206d1dbc8b4868f2402dbcf88a20bd60297ed66dab1279deb7f3407468e3a05bf3d2c7a217d4345442ec790eb054acbcea988348
|
7
|
+
data.tar.gz: e3cee84345893f9cae5ec6a83740164cf5f4cc38b51295520e84f7dcf735a6f6bca21cac01c669b3c513bebb2f322029fd296214085442d1c8df8cb9d55e4790
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/conduct.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
|
2
|
+
# Contributor Covenant Code of Conduct
|
3
|
+
|
4
|
+
## Our Pledge
|
5
|
+
|
6
|
+
We as members, contributors, and leaders pledge to make participation in our
|
7
|
+
community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
9
|
+
identity and expression, level of experience, education, socio-economic status,
|
10
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
11
|
+
identity and orientation.
|
12
|
+
|
13
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
14
|
+
diverse, inclusive, and healthy community.
|
15
|
+
|
16
|
+
## Our Standards
|
17
|
+
|
18
|
+
Examples of behavior that contributes to a positive environment for our
|
19
|
+
community include:
|
20
|
+
|
21
|
+
* Demonstrating empathy and kindness toward other people
|
22
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
23
|
+
* Giving and gracefully accepting constructive feedback
|
24
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
25
|
+
and learning from the experience
|
26
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
27
|
+
community
|
28
|
+
|
29
|
+
Examples of unacceptable behavior include:
|
30
|
+
|
31
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
32
|
+
any kind
|
33
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
34
|
+
* Public or private harassment
|
35
|
+
* Publishing others' private information, such as a physical or email address,
|
36
|
+
without their explicit permission
|
37
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
38
|
+
professional setting
|
39
|
+
|
40
|
+
## Enforcement Responsibilities
|
41
|
+
|
42
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
43
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
44
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
45
|
+
or harmful.
|
46
|
+
|
47
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
48
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
49
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
50
|
+
decisions when appropriate.
|
51
|
+
|
52
|
+
## Scope
|
53
|
+
|
54
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
55
|
+
an individual is officially representing the community in public spaces.
|
56
|
+
Examples of representing our community include using an official e-mail address,
|
57
|
+
posting via an official social media account, or acting as an appointed
|
58
|
+
representative at an online or offline event.
|
59
|
+
|
60
|
+
## Enforcement
|
61
|
+
|
62
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
63
|
+
reported to the community leaders responsible for enforcement at
|
64
|
+
[INSERT CONTACT METHOD].
|
65
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
66
|
+
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
68
|
+
reporter of any incident.
|
69
|
+
|
70
|
+
## Enforcement Guidelines
|
71
|
+
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
74
|
+
|
75
|
+
### 1. Correction
|
76
|
+
|
77
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
78
|
+
unprofessional or unwelcome in the community.
|
79
|
+
|
80
|
+
**Consequence**: A private, written warning from community leaders, providing
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
83
|
+
|
84
|
+
### 2. Warning
|
85
|
+
|
86
|
+
**Community Impact**: A violation through a single incident or series of
|
87
|
+
actions.
|
88
|
+
|
89
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
93
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
94
|
+
ban.
|
95
|
+
|
96
|
+
### 3. Temporary Ban
|
97
|
+
|
98
|
+
**Community Impact**: A serious violation of community standards, including
|
99
|
+
sustained inappropriate behavior.
|
100
|
+
|
101
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
102
|
+
communication with the community for a specified period of time. No public or
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
105
|
+
Violating these terms may lead to a permanent ban.
|
106
|
+
|
107
|
+
### 4. Permanent Ban
|
108
|
+
|
109
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
112
|
+
|
113
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
114
|
+
community.
|
115
|
+
|
116
|
+
## Attribution
|
117
|
+
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
119
|
+
version 2.1, available at
|
120
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
121
|
+
|
122
|
+
Community Impact Guidelines were inspired by
|
123
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
124
|
+
|
125
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
126
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
127
|
+
[https://www.contributor-covenant.org/translations][translations].
|
128
|
+
|
129
|
+
[homepage]: https://www.contributor-covenant.org
|
130
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
131
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
132
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
133
|
+
[translations]: https://www.contributor-covenant.org/translations
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2023, by Bruno Sutic.
|
5
6
|
|
6
7
|
module Protocol
|
7
8
|
module HTTP
|
@@ -66,11 +67,15 @@ module Protocol
|
|
66
67
|
|
67
68
|
# Enumerate all chunks until finished, then invoke `#close`.
|
68
69
|
def each
|
69
|
-
|
70
|
-
|
70
|
+
return to_enum(:each) unless block_given?
|
71
|
+
|
72
|
+
begin
|
73
|
+
while chunk = self.read
|
74
|
+
yield chunk
|
75
|
+
end
|
76
|
+
ensure
|
77
|
+
self.close($!)
|
71
78
|
end
|
72
|
-
ensure
|
73
|
-
self.close($!)
|
74
79
|
end
|
75
80
|
|
76
81
|
# Read all remaining chunks into a single binary string using `#each`.
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2023, by Genki Takiuchi.
|
5
6
|
|
6
7
|
require_relative 'buffered'
|
7
8
|
|
@@ -19,6 +20,7 @@ module Protocol
|
|
19
20
|
# Will hold remaining data in `#read`.
|
20
21
|
@buffer = nil
|
21
22
|
@closed = false
|
23
|
+
@closed_read = false
|
22
24
|
end
|
23
25
|
|
24
26
|
attr :input
|
@@ -146,6 +148,9 @@ module Protocol
|
|
146
148
|
end
|
147
149
|
|
148
150
|
def close_read
|
151
|
+
@closed_read = true
|
152
|
+
@buffer = nil
|
153
|
+
|
149
154
|
@input&.close
|
150
155
|
@input = nil
|
151
156
|
end
|
@@ -181,8 +186,7 @@ module Protocol
|
|
181
186
|
def read_next
|
182
187
|
if @input
|
183
188
|
return @input.read
|
184
|
-
|
185
|
-
@input = nil
|
189
|
+
elsif @closed_read
|
186
190
|
raise IOError, "Stream is not readable, input has been closed!"
|
187
191
|
end
|
188
192
|
end
|
@@ -5,19 +5,50 @@
|
|
5
5
|
|
6
6
|
module Protocol
|
7
7
|
module HTTP
|
8
|
-
#
|
8
|
+
# Provides a convenient interface for commonly supported HTTP methods.
|
9
|
+
#
|
10
|
+
# | Method Name | Request Body | Response Body | Safe | Idempotent | Cacheable |
|
11
|
+
# | ----------- | ------------ | ------------- | ---- | ---------- | --------- |
|
12
|
+
# | GET | Optional | Yes | Yes | Yes | Yes |
|
13
|
+
# | HEAD | Optional | No | Yes | Yes | Yes |
|
14
|
+
# | POST | Yes | Yes | No | No | Yes |
|
15
|
+
# | PUT | Yes | Yes | No | Yes | No |
|
16
|
+
# | DELETE | Optional | Yes | No | Yes | No |
|
17
|
+
# | CONNECT | Optional | Yes | No | No | No |
|
18
|
+
# | OPTIONS | Optional | Yes | Yes | Yes | No |
|
19
|
+
# | TRACE | No | Yes | Yes | Yes | No |
|
20
|
+
# | PATCH | Yes | Yes | No | No | No |
|
21
|
+
#
|
22
|
+
# These methods are defined in this module using lower case names. They are for convenience only and you should not overload those methods.
|
23
|
+
#
|
24
|
+
# See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods> for more details.
|
9
25
|
class Methods
|
26
|
+
# The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
|
10
27
|
GET = 'GET'
|
28
|
+
|
29
|
+
# The HEAD method asks for a response identical to a GET request, but without the response body.
|
30
|
+
HEAD = 'HEAD'
|
31
|
+
|
32
|
+
# The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server.
|
11
33
|
POST = 'POST'
|
34
|
+
|
35
|
+
# The PUT method replaces all current representations of the target resource with the request payload.
|
12
36
|
PUT = 'PUT'
|
13
|
-
|
37
|
+
|
38
|
+
# The DELETE method deletes the specified resource.
|
14
39
|
DELETE = 'DELETE'
|
15
|
-
|
40
|
+
|
41
|
+
# The CONNECT method establishes a tunnel to the server identified by the target resource.
|
42
|
+
CONNECT = 'CONNECT'
|
43
|
+
|
44
|
+
# The OPTIONS method describes the communication options for the target resource.
|
16
45
|
OPTIONS = 'OPTIONS'
|
17
|
-
|
18
|
-
|
46
|
+
|
47
|
+
# The TRACE method performs a message loop-back test along the path to the target resource.
|
19
48
|
TRACE = 'TRACE'
|
20
|
-
|
49
|
+
|
50
|
+
# The PATCH method applies partial modifications to a resource.
|
51
|
+
PATCH = 'PATCH'
|
21
52
|
|
22
53
|
def self.valid?(name)
|
23
54
|
const_defined?(name)
|
@@ -26,13 +57,18 @@ module Protocol
|
|
26
57
|
return false
|
27
58
|
end
|
28
59
|
|
60
|
+
# Enumerate all HTTP methods.
|
61
|
+
# @yields {|name, value| ...}
|
62
|
+
# @parameter name [Symbol] The name of the method, e.g. `:GET`.
|
63
|
+
# @parameter value [String] The value of the method, e.g. `"GET"`.
|
29
64
|
def self.each
|
65
|
+
return to_enum(:each) unless block_given?
|
66
|
+
|
30
67
|
constants.each do |name|
|
31
68
|
yield name, const_get(name)
|
32
69
|
end
|
33
70
|
end
|
34
71
|
|
35
|
-
# Use Methods.constants to get all constants.
|
36
72
|
self.each do |name, value|
|
37
73
|
define_method(name.downcase) do |location, headers = nil, body = nil|
|
38
74
|
self.call(
|
@@ -14,12 +14,10 @@ module Protocol
|
|
14
14
|
@app = default_app
|
15
15
|
end
|
16
16
|
|
17
|
-
def use(middleware, *arguments, &block)
|
18
|
-
@use << proc {|app| middleware.new(app, *arguments, &block)}
|
17
|
+
def use(middleware, *arguments, **options, &block)
|
18
|
+
@use << proc {|app| middleware.new(app, *arguments, **options, &block)}
|
19
19
|
end
|
20
20
|
|
21
|
-
ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
|
22
|
-
|
23
21
|
def run(app)
|
24
22
|
@app = app
|
25
23
|
end
|
@@ -10,6 +10,16 @@ require_relative 'response'
|
|
10
10
|
|
11
11
|
module Protocol
|
12
12
|
module HTTP
|
13
|
+
# The middleware interface provides a convenient wrapper for implementing HTTP middleware.
|
14
|
+
#
|
15
|
+
# A middleware instance generally needs to respond to two methods:
|
16
|
+
#
|
17
|
+
# - `call(request)` -> `response`
|
18
|
+
# - `close()`
|
19
|
+
#
|
20
|
+
# The call method is called for each request. The close method is called when the server is shutting down.
|
21
|
+
#
|
22
|
+
# You do not need to use the Middleware class to implement middleware. You can implement the interface directly.
|
13
23
|
class Middleware < Methods
|
14
24
|
# Convert a block to a middleware delegate.
|
15
25
|
def self.for(&block)
|
data/license.md
CHANGED
@@ -4,9 +4,10 @@ Copyright, 2018-2023, by Samuel Williams.
|
|
4
4
|
Copyright, 2019, by Yuta Iwama.
|
5
5
|
Copyright, 2020, by Olle Jonsson.
|
6
6
|
Copyright, 2020, by Bryan Powell.
|
7
|
-
Copyright, 2020, by Bruno Sutic.
|
7
|
+
Copyright, 2020-2023, by Bruno Sutic.
|
8
8
|
Copyright, 2022, by Herrick Fang.
|
9
9
|
Copyright, 2022, by Dan Olson.
|
10
|
+
Copyright, 2023, by Genki Takiuchi.
|
10
11
|
|
11
12
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
13
|
of this software and associated documentation files (the "Software"), to deal
|
data/readme.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
Provides abstractions for working with the HTTP protocol.
|
4
4
|
|
5
|
-
[](https://github.com/socketry/protocol-http/actions?workflow=Test)
|
6
7
|
|
7
8
|
## Features
|
8
9
|
|
@@ -12,7 +13,14 @@ Provides abstractions for working with the HTTP protocol.
|
|
12
13
|
|
13
14
|
## Usage
|
14
15
|
|
15
|
-
Please see the [project documentation](https://
|
16
|
+
Please see the [project documentation](https://github.com/socketry/protocol-http) for more details.
|
17
|
+
|
18
|
+
- [Getting Started](https://github.com/socketry/protocol-httpguides/getting-started/index) - This guide explains how
|
19
|
+
to use `protocol-http` for building abstract HTTP interfaces.
|
20
|
+
|
21
|
+
- [Design Overview](https://github.com/socketry/protocol-httpguides/design-overview/index) - The interfaces provided
|
22
|
+
by <code class="language-ruby">Protocol::HTTP</code> underpin all downstream implementations. Therefore, we provide
|
23
|
+
some justification for the design choices.
|
16
24
|
|
17
25
|
## Contributing
|
18
26
|
|
@@ -26,7 +34,10 @@ We welcome contributions to this project.
|
|
26
34
|
|
27
35
|
## See Also
|
28
36
|
|
29
|
-
- [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this
|
30
|
-
|
31
|
-
- [
|
37
|
+
- [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this
|
38
|
+
interface.
|
39
|
+
- [protocol-http2](https://github.com/socketry/protocol-http2) — HTTP/2 client/server implementation using this
|
40
|
+
interface.
|
41
|
+
- [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client and server, supporting multiple HTTP
|
42
|
+
protocols & TLS.
|
32
43
|
- [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server WebSockets.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.24.
|
4
|
+
version: 0.24.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
- Herrick Fang
|
9
8
|
- Bruno Sutic
|
9
|
+
- Herrick Fang
|
10
10
|
- Bryan Powell
|
11
11
|
- Dan Olson
|
12
|
+
- Genki Takiuchi
|
12
13
|
- Olle Jonsson
|
13
14
|
- Yuta Iwama
|
14
15
|
autorequire:
|
@@ -43,7 +44,7 @@ cert_chain:
|
|
43
44
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
44
45
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
45
46
|
-----END CERTIFICATE-----
|
46
|
-
date: 2023-06-
|
47
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
47
48
|
dependencies:
|
48
49
|
- !ruby/object:Gem::Dependency
|
49
50
|
name: bundler
|
@@ -93,6 +94,7 @@ executables: []
|
|
93
94
|
extensions: []
|
94
95
|
extra_rdoc_files: []
|
95
96
|
files:
|
97
|
+
- conduct.md
|
96
98
|
- design.md
|
97
99
|
- lib/protocol/http.rb
|
98
100
|
- lib/protocol/http/accept_encoding.rb
|
metadata.gz.sig
CHANGED
Binary file
|