protocol-http 0.24.3 → 0.24.5

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: e2395576c8aba120a122bc6f5855a3cb3b98c7fbbbc5b3cb8ce9c6a03428ac60
4
- data.tar.gz: 4b20aa1a240517db6318ed8a0e34e4a86b928f34b28bd62faae5ae7ad565d149
3
+ metadata.gz: eb00073aae0383b460c8cc2138ac73fc9280407c3066ed57b5baf77ea88b3472
4
+ data.tar.gz: cea4d88baacbe398003f00540ee409e94578c5089f8ed46c9a0ccb9ad9c88dca
5
5
  SHA512:
6
- metadata.gz: 69c8da38bf38207c0b815973b6de1286066ef606717d1b20f13af2e79ed2ede88c932c3656ee178d522cd934ddd4c17b3a8c12749b332b6db9f10ee8cf503a2f
7
- data.tar.gz: 6846f00a5d65e3230228bfdfd9e94d76372ca0528b6977fcd9c8ebf1f647a21793a4bfd340b818950c1a5e5f74e884d815176067ea56b353a5838c14e582aabe
6
+ metadata.gz: c7ad4d6fdd17b190b64591c9b1141d568d053804164e6129fb09fe095858a4770c75c5dd79e6fa40ca5dcc5a912b2535d92cfd8f3ba514b1145212b3d927a609
7
+ data.tar.gz: '08ff03c85eba73b43a640fb7a03be09dc782334b9bc8b0d67c33abeb51bc9ef26070436a01327a9946d15f1e28f408c95028ce2f30d168655b25b09cd70886be'
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
- while chunk = self.read
70
- yield chunk
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
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2023, by Samuel Williams.
5
+
6
+ require 'time'
7
+
8
+ module Protocol
9
+ module HTTP
10
+ module Header
11
+ class Date < String
12
+ def << value
13
+ replace(value)
14
+ end
15
+
16
+ def to_time
17
+ ::Time.parse(self)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -12,6 +12,7 @@ require_relative 'header/etag'
12
12
  require_relative 'header/etags'
13
13
  require_relative 'header/vary'
14
14
  require_relative 'header/authorization'
15
+ require_relative 'header/date'
15
16
 
16
17
  module Protocol
17
18
  module HTTP
@@ -239,6 +240,9 @@ module Protocol
239
240
  # Custom headers:
240
241
  'set-cookie' => Header::SetCookie,
241
242
  'cookie' => Header::Cookie,
243
+
244
+ 'date' => Header::Date,
245
+ 'expires' => Header::Date,
242
246
  }.tap{|hash| hash.default = Split}
243
247
 
244
248
  # Delete all headers with the given key, and return the merged value.
@@ -5,19 +5,50 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- # All supported HTTP methods
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
- PATCH = 'PATCH'
37
+
38
+ # The DELETE method deletes the specified resource.
14
39
  DELETE = 'DELETE'
15
- HEAD = 'HEAD'
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
- LINK = 'LINK'
18
- UNLINK = 'UNLINK'
46
+
47
+ # The TRACE method performs a message loop-back test along the path to the target resource.
19
48
  TRACE = 'TRACE'
20
- CONNECT = 'CONNECT'
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)
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.24.3"
8
+ VERSION = "0.24.5"
9
9
  end
10
10
  end
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
@@ -12,7 +12,14 @@ Provides abstractions for working with the HTTP protocol.
12
12
 
13
13
  ## Usage
14
14
 
15
- Please see the [project documentation](https://socketry.github.io/protocol-http).
15
+ Please see the [project documentation](https://github.com/socketry/protocol-http) for more details.
16
+
17
+ - [Getting Started](https://github.com/socketry/protocol-httpguides/getting-started/index) - This guide explains how
18
+ to use `protocol-http` for building abstract HTTP interfaces.
19
+
20
+ - [Design Overview](https://github.com/socketry/protocol-httpguides/design-overview/index) - The interfaces provided
21
+ by <code class="language-ruby">Protocol::HTTP</code> underpin all downstream implementations. Therefore, we provide
22
+ some justification for the design choices.
16
23
 
17
24
  ## Contributing
18
25
 
@@ -24,9 +31,20 @@ We welcome contributions to this project.
24
31
  4. Push to the branch (`git push origin my-new-feature`).
25
32
  5. Create new Pull Request.
26
33
 
34
+ ### Developer Certificate of Origin
35
+
36
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
37
+
38
+ ### Contributor Covenant
39
+
40
+ This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
41
+
27
42
  ## See Also
28
43
 
29
- - [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this interface.
30
- - [protocol-http2](https://github.com/socketry/protocol-http2) — HTTP/2 client/server implementation using this interface.
31
- - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client and server, supporting multiple HTTP protocols & TLS.
44
+ - [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this
45
+ interface.
46
+ - [protocol-http2](https://github.com/socketry/protocol-http2) — HTTP/2 client/server implementation using this
47
+ interface.
48
+ - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client and server, supporting multiple HTTP
49
+ protocols & TLS.
32
50
  - [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.3
4
+ version: 0.24.5
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,50 +44,8 @@ cert_chain:
43
44
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
44
45
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
45
46
  -----END CERTIFICATE-----
46
- date: 2023-06-10 00:00:00.000000000 Z
47
- dependencies:
48
- - !ruby/object:Gem::Dependency
49
- name: bundler
50
- requirement: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: covered
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- type: :development
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- - !ruby/object:Gem::Dependency
77
- name: sus
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- type: :development
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
47
+ date: 2023-08-02 00:00:00.000000000 Z
48
+ dependencies: []
90
49
  description:
91
50
  email:
92
51
  executables: []
@@ -115,6 +74,7 @@ files:
115
74
  - lib/protocol/http/header/cache_control.rb
116
75
  - lib/protocol/http/header/connection.rb
117
76
  - lib/protocol/http/header/cookie.rb
77
+ - lib/protocol/http/header/date.rb
118
78
  - lib/protocol/http/header/etag.rb
119
79
  - lib/protocol/http/header/etags.rb
120
80
  - lib/protocol/http/header/multiple.rb
@@ -143,14 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
103
  requirements:
144
104
  - - ">="
145
105
  - !ruby/object:Gem::Version
146
- version: '2.5'
106
+ version: 2.7.6
147
107
  required_rubygems_version: !ruby/object:Gem::Requirement
148
108
  requirements:
149
109
  - - ">="
150
110
  - !ruby/object:Gem::Version
151
111
  version: '0'
152
112
  requirements: []
153
- rubygems_version: 3.4.7
113
+ rubygems_version: 3.4.10
154
114
  signing_key:
155
115
  specification_version: 4
156
116
  summary: Provides abstractions to handle HTTP protocols.
metadata.gz.sig CHANGED
Binary file