Skip to content

Commit 1aa0a40

Browse files
committed
WIP
1 parent ad3ae56 commit 1aa0a40

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

lib/async/http/protocol/configurable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def client(peer, **options)
2525

2626
def server(peer, **options)
2727
options = @options.merge(options)
28-
@protocol.server(peer, options)
28+
@protocol.server(peer, **options)
2929
end
3030

3131
def names

lib/async/http/protocol/defaulton.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ module Protocol
99
# This module provides a default instance of the protocol, which can be used to create clients and servers. The name is a play on "Default" + "Singleton".
1010
module Defaulton
1111
def self.extended(base)
12-
base.const_set(:DEFAULT, base.new)
12+
base.instance_variable_set(:@default, base.new)
1313
end
1414

15-
# The default instance of the protocol.
16-
def default
17-
self::DEFAULT
18-
end
15+
attr_accessor :default
1916

2017
# Create a client for an outbound connection, using the default instance.
2118
def client(peer, **options)

releases.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Releases
22

3+
## Unreleased
4+
5+
### Support custom protocols with options
6+
7+
{ruby Async::HTTP::Protocol} contains classes for specific protocols, e.g. {ruby Async::HTTP::Protocol::HTTP1} and {ruby Async::HTTP::Protocol::HTTP2}. It also contains classes for aggregating protocols, e.g. {ruby Async::HTTP::Protocol::HTTP} and {ruby Async::HTTP::Protocol::HTTPS}. They serve as factories for creating client and server instances.
8+
9+
These classes are now configurable with various options, which are passed as keyword arguments to the relevant connection classes. For example, to configure an HTTP/1.1 protocol without keep-alive:
10+
11+
```ruby
12+
protocol = Async::HTTP::Protocol::HTTP1.new(persistent: false, maximum_line_length: 32)
13+
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292", protocol: protocol)
14+
server = Async::HTTP::Server.for(endpoint) do |request|
15+
Protocol::HTTP::Response[200, {}, ["Hello, world"]]
16+
end.run
17+
```
18+
319
## v0.87.0
420

521
### Unify HTTP/1 and HTTP/2 `CONNECT` semantics

test/async/http/protocol/http.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
require "async/http/a_protocol"
99

1010
describe Async::HTTP::Protocol::HTTP do
11+
let(:protocol) {subject.default}
12+
13+
with ".default" do
14+
it "has a default instance" do
15+
expect(subject.default).to be_a Async::HTTP::Protocol::HTTP
16+
end
17+
end
18+
1119
with "#protocol_for" do
12-
let(:protocol) {subject::DEFAULT}
1320
let(:buffer) {StringIO.new}
1421

1522
it "it can detect http/1.1" do

0 commit comments

Comments
 (0)