protocol-http 0.29.0 → 0.30.0

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: e5839d2adb8415083224423beb2d5a3c0a50e22090a75424276e1a0939cc800a
4
- data.tar.gz: 0517ecffe3b1f6c486b1cba2b5cbf4b3b7a8daf2cb11469b73d0d61cb5492cb1
3
+ metadata.gz: 5365fcaf109db92e1db6bc6389e881881f7ec19c4f1bcd747b16d72698e89a7c
4
+ data.tar.gz: 11f68df5f5b9370579764e475a0fe1579c3b4d2f06aaed80efb0cb5fa5c6e392
5
5
  SHA512:
6
- metadata.gz: 5fe865bc6ae53bfbd34ca9e43c6c38d2dcb3874b0655b1960936960b690cfefc0203ecde64ea7ea3af17a8a1093382d98f419e5d88b24708af99ef210a282e7e
7
- data.tar.gz: 5c576ba8d79c0c6d21022d224b936f307640e2a785685cb82ec2eb0da588fcc8cbb215d2b7a05572ab91274978acc1f3a39edc0dfb5946fbef32dafa51389296
6
+ metadata.gz: 05f867a38d373f1491630bc5a9bf30401b8ac0fa41cec5392787a1fb916d42fa0f14ff8b80078b89246ab5bbdaae40b2dd67b77302571e3cb0803477e48ead4f
7
+ data.tar.gz: dbb7ac119a2d46c5150b8a274c89280582d69f64718849a7537d0a4b876f40c0b9a36c47fc3e2d6f27a244e12465d4ba372a3e4c87c7d0e1c738c0757cd672d5
checksums.yaml.gz.sig CHANGED
Binary file
@@ -70,9 +70,9 @@ module Protocol
70
70
  end
71
71
 
72
72
  self.each do |name, value|
73
- define_method(name) do |location, headers = nil, body = nil|
73
+ define_method(name) do |location, *arguments, **options|
74
74
  self.call(
75
- Request[value, location.to_s, Headers[headers], body]
75
+ Request[value, location.to_s, *arguments, **options]
76
76
  )
77
77
  end
78
78
  end
@@ -25,7 +25,7 @@ module Protocol
25
25
  class Request
26
26
  prepend Body::Reader
27
27
 
28
- def initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil)
28
+ def initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil, interim_response = nil)
29
29
  @scheme = scheme
30
30
  @authority = authority
31
31
  @method = method
@@ -34,6 +34,7 @@ module Protocol
34
34
  @headers = headers
35
35
  @body = body
36
36
  @protocol = protocol
37
+ @interim_response = interim_response
37
38
  end
38
39
 
39
40
  # @attribute [String] the request scheme, usually `"http"` or `"https"`.
@@ -60,11 +61,30 @@ module Protocol
60
61
  # @attribute [String | Array(String) | Nil] the request protocol, usually empty, but occasionally `"websocket"` or `"webtransport"`. 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.
61
62
  attr_accessor :protocol
62
63
 
64
+ # @attribute [Proc] a callback which is called when an interim response is received.
65
+ attr_accessor :interim_response
66
+
63
67
  # Send the request to the given connection.
64
68
  def call(connection)
65
69
  connection.call(self)
66
70
  end
67
71
 
72
+ # Send an interim response back to the origin of this request, if possible.
73
+ def send_interim_response(status, headers)
74
+ @interim_response&.call(status, headers)
75
+ end
76
+
77
+ def on_interim_response(&block)
78
+ if interim_response = @interim_response
79
+ @interim_response = ->(status, headers) do
80
+ block.call(status, headers)
81
+ interim_response.call(status, headers)
82
+ end
83
+ else
84
+ @interim_response = block
85
+ end
86
+ end
87
+
68
88
  # Whether this is a HEAD request: no body is expected in the response.
69
89
  def head?
70
90
  @method == Methods::HEAD
@@ -81,11 +101,11 @@ module Protocol
81
101
  # @parameter path [String] The path, e.g. `"/index.html"`, `"/search?q=hello"`, etc.
82
102
  # @parameter headers [Hash] The headers, e.g. `{"accept" => "text/html"}`, etc.
83
103
  # @parameter body [String | Array(String) | Body::Readable] The body, e.g. `"Hello, World!"`, etc. See {Body::Buffered.wrap} for more information about .
84
- def self.[](method, path, headers = nil, body = nil)
104
+ def self.[](method, path, _headers = nil, _body = nil, scheme: nil, authority: nil, headers: _headers, body: _body, protocol: nil, interim_response: nil)
85
105
  body = Body::Buffered.wrap(body)
86
- headers = ::Protocol::HTTP::Headers[headers]
106
+ headers = Headers[headers]
87
107
 
88
- self.new(nil, nil, method, path, nil, headers, body)
108
+ self.new(scheme, authority, method, path, nil, headers, body, protocol, interim_response)
89
109
  end
90
110
 
91
111
  # Whether the request can be replayed without side-effects.
@@ -130,9 +130,9 @@ module Protocol
130
130
  # @parameter status [Integer] The HTTP status code, e.g. `200`, `404`, etc.
131
131
  # @parameter headers [Hash] The headers, e.g. `{"content-type" => "text/html"}`, etc.
132
132
  # @parameter body [String | Array(String) | Body::Readable] The body, e.g. `"Hello, World!"`, etc. See {Body::Buffered.wrap} for more information about .
133
- def self.[](status, headers = nil, body = nil, protocol = nil)
133
+ def self.[](status, _headers = nil, _body = nil, headers: _headers, body: _body, protocol: nil)
134
134
  body = Body::Buffered.wrap(body)
135
- headers = ::Protocol::HTTP::Headers[headers]
135
+ headers = Headers[headers]
136
136
 
137
137
  self.new(nil, status, headers, body, protocol)
138
138
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.29.0"
8
+ VERSION = "0.30.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -18,6 +18,25 @@ Please see the [project documentation](https://socketry.github.io/protocol-http/
18
18
 
19
19
  - [Design Overview](https://socketry.github.io/protocol-http/guides/design-overview/index) - This guide explains the high level design of `protocol-http` in the context of wider design patterns that can be used to implement HTTP clients and servers.
20
20
 
21
+ ## Releases
22
+
23
+ Please see the [project releases](https://socketry.github.io/protocol-http/releases/index) for all releases.
24
+
25
+ ### Unreleased
26
+
27
+ - [`Request[]` and `Response[]` Keyword Arguments](https://socketry.github.io/protocol-http/releases/index#request[]-and-response[]-keyword-arguments)
28
+ - [Interim Response Handling](https://socketry.github.io/protocol-http/releases/index#interim-response-handling)
29
+
30
+ ## See Also
31
+
32
+ - [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this
33
+ interface.
34
+ - [protocol-http2](https://github.com/socketry/protocol-http2) — HTTP/2 client/server implementation using this
35
+ interface.
36
+ - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client and server, supporting multiple HTTP
37
+ protocols & TLS.
38
+ - [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server WebSockets.
39
+
21
40
  ## Contributing
22
41
 
23
42
  We welcome contributions to this project.
@@ -35,13 +54,3 @@ In order to protect users of this project, we require all contributors to comply
35
54
  ### Community Guidelines
36
55
 
37
56
  This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
38
-
39
- ## See Also
40
-
41
- - [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this
42
- interface.
43
- - [protocol-http2](https://github.com/socketry/protocol-http2) — HTTP/2 client/server implementation using this
44
- interface.
45
- - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client and server, supporting multiple HTTP
46
- protocols & TLS.
47
- - [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server WebSockets.
data/releases.md ADDED
@@ -0,0 +1,40 @@
1
+ # Releases
2
+
3
+ ## Unreleased
4
+
5
+ ### `Request[]` and `Response[]` Keyword Arguments
6
+
7
+ The `Request[]` and `Response[]` methods now support keyword arguments as a convenient way to set various positional arguments.
8
+
9
+ ```ruby
10
+ # Request keyword arguments:
11
+ client.get("/", headers: {"accept" => "text/html"}, authority: "example.com")
12
+
13
+ # Response keyword arguments:
14
+ def call(request)
15
+ return Response[200, headers: {"content-Type" => "text/html"}, body: "Hello, World!"]
16
+ ```
17
+
18
+ ### Interim Response Handling
19
+
20
+ The `Request` class now exposes a `#interim_response` attribute which can be used to handle interim responses both on the client side and server side.
21
+
22
+ On the client side, you can pass a callback using the `interim_response` keyword argument which will be invoked whenever an interim response is received:
23
+
24
+ ```ruby
25
+ client = ...
26
+ response = client.get("/index", interim_response: proc{|status, headers| ...})
27
+ ```
28
+
29
+ On the server side, you can send an interim response using the `#send_interim_response` method:
30
+
31
+ ```ruby
32
+ def call(request)
33
+ if request.headers["expect"] == "100-continue"
34
+ # Send an interim response:
35
+ request.send_interim_response(100)
36
+ end
37
+
38
+ # ...
39
+ end
40
+ ```
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.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -47,7 +47,7 @@ cert_chain:
47
47
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
48
48
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
49
49
  -----END CERTIFICATE-----
50
- date: 2024-08-28 00:00:00.000000000 Z
50
+ date: 2024-08-30 00:00:00.000000000 Z
51
51
  dependencies: []
52
52
  description:
53
53
  email:
@@ -93,6 +93,7 @@ files:
93
93
  - lib/protocol/http/version.rb
94
94
  - license.md
95
95
  - readme.md
96
+ - releases.md
96
97
  homepage: https://github.com/socketry/protocol-http
97
98
  licenses:
98
99
  - MIT
metadata.gz.sig CHANGED
Binary file