Skip to content

Commit 722cd78

Browse files
committed
Add example of plaintext HTTP/1 and HTTP/2.
1 parent 1e4fc00 commit 722cd78

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

examples/hello/config.ru

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env falcon --verbose serve -c
2+
# frozen_string_literal: true
3+
4+
require 'async'
5+
require 'async/barrier'
6+
require 'net/http'
7+
require 'uri'
8+
9+
run do |env|
10+
i = 1_000_000
11+
while i > 0
12+
i -= 1
13+
end
14+
15+
[200, {}, ["Hello World!"]]
16+
end

examples/hello/gems.locked

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
PATH
2+
remote: ../..
3+
specs:
4+
async-http (0.66.3)
5+
async (>= 2.10.2)
6+
async-pool (>= 0.6.1)
7+
io-endpoint (~> 0.10, >= 0.10.3)
8+
io-stream (~> 0.4)
9+
protocol-http (~> 0.26.0)
10+
protocol-http1 (~> 0.19.0)
11+
protocol-http2 (~> 0.17.0)
12+
traces (>= 0.10.0)
13+
14+
GEM
15+
remote: https://rubygems.org/
16+
specs:
17+
async (2.12.0)
18+
console (~> 1.25, >= 1.25.2)
19+
fiber-annotation
20+
io-event (~> 1.6)
21+
async-container (0.18.2)
22+
async (~> 2.10)
23+
async-http-cache (0.4.3)
24+
async-http (~> 0.56)
25+
async-pool (0.6.1)
26+
async (>= 1.25)
27+
async-service (0.12.0)
28+
async
29+
async-container (~> 0.16)
30+
console (1.25.2)
31+
fiber-annotation
32+
fiber-local (~> 1.1)
33+
json
34+
falcon (0.47.6)
35+
async
36+
async-container (~> 0.18)
37+
async-http (~> 0.66, >= 0.66.3)
38+
async-http-cache (~> 0.4.0)
39+
async-service (~> 0.10)
40+
bundler
41+
localhost (~> 1.1)
42+
openssl (~> 3.0)
43+
process-metrics (~> 0.2.0)
44+
protocol-rack (~> 0.5)
45+
samovar (~> 2.3)
46+
fiber-annotation (0.2.0)
47+
fiber-local (1.1.0)
48+
fiber-storage
49+
fiber-storage (0.1.1)
50+
io-endpoint (0.10.3)
51+
io-event (1.6.0)
52+
io-stream (0.4.0)
53+
json (2.7.2)
54+
localhost (1.3.1)
55+
mapping (1.1.1)
56+
openssl (3.2.0)
57+
process-metrics (0.2.1)
58+
console (~> 1.8)
59+
samovar (~> 2.1)
60+
protocol-hpack (1.4.3)
61+
protocol-http (0.26.5)
62+
protocol-http1 (0.19.1)
63+
protocol-http (~> 0.22)
64+
protocol-http2 (0.17.0)
65+
protocol-hpack (~> 1.4)
66+
protocol-http (~> 0.18)
67+
protocol-rack (0.5.1)
68+
protocol-http (~> 0.23)
69+
rack (>= 1.0)
70+
rack (3.0.11)
71+
samovar (2.3.0)
72+
console (~> 1.0)
73+
mapping (~> 1.0)
74+
traces (0.11.1)
75+
76+
PLATFORMS
77+
arm64-darwin-23
78+
ruby
79+
80+
DEPENDENCIES
81+
async-http!
82+
falcon
83+
84+
BUNDLED WITH
85+
2.5.9

examples/hello/gems.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "https://rubygems.org"
2+
3+
gem "async-http", path: "../../"
4+
gem "falcon"

examples/hello/readme.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Hello Example
2+
3+
## Server
4+
5+
```bash
6+
$ bundle update
7+
$ bundle exec falcon serve --bind http://localhost:3000
8+
```
9+
10+
## Client
11+
12+
### HTTP/1
13+
14+
```bash
15+
$ curl -v http://localhost:3000
16+
* Host localhost:3000 was resolved.
17+
* IPv6: ::1
18+
* IPv4: 127.0.0.1
19+
* Trying [::1]:3000...
20+
* Connected to localhost (::1) port 3000
21+
> GET / HTTP/1.1
22+
> Host: localhost:3000
23+
> User-Agent: curl/8.7.1
24+
> Accept: */*
25+
>
26+
* Request completely sent off
27+
< HTTP/1.1 200 OK
28+
< vary: accept-encoding
29+
< content-length: 12
30+
<
31+
* Connection #0 to host localhost left intact
32+
Hello World!
33+
```
34+
35+
### HTTP/2
36+
37+
```bash
38+
$ curl -v --http2-prior-knowledge http://localhost:3000
39+
* Host localhost:3000 was resolved.
40+
* IPv6: ::1
41+
* IPv4: 127.0.0.1
42+
* Trying [::1]:3000...
43+
* Connected to localhost (::1) port 3000
44+
* [HTTP/2] [1] OPENED stream for http://localhost:3000/
45+
* [HTTP/2] [1] [:method: GET]
46+
* [HTTP/2] [1] [:scheme: http]
47+
* [HTTP/2] [1] [:authority: localhost:3000]
48+
* [HTTP/2] [1] [:path: /]
49+
* [HTTP/2] [1] [user-agent: curl/8.7.1]
50+
* [HTTP/2] [1] [accept: */*]
51+
> GET / HTTP/2
52+
> Host: localhost:3000
53+
> User-Agent: curl/8.7.1
54+
> Accept: */*
55+
>
56+
* Request completely sent off
57+
< HTTP/2 200
58+
< content-length: 12
59+
< vary: accept-encoding
60+
<
61+
* Connection #0 to host localhost left intact
62+
Hello World!
63+
```

0 commit comments

Comments
 (0)