Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 56 lines (42 sloc) 1.358 kB
57520c4 @igrigorik simple EM spdy server example
authored
1 $: << 'lib' << '../lib'
2
3 require 'eventmachine'
4 require 'spdy'
5
6 class SPDYHandler < EM::Connection
7 def post_init
8 @parser = SPDY::Parser.new
cfef951 @igrigorik update example to new API, drop TLS
authored
9 @parser.on_headers do |stream_id, headers|
c967ba8 @igrigorik update example server
authored
10 p [:SPDY_HEADERS, headers]
57520c4 @igrigorik simple EM spdy server example
authored
11
d0cd597 @carsonmcdonald Reworked compression so that it spans the life of a session.
carsonmcdonald authored
12 sr = SPDY::Protocol::Control::SynReply.new({:zlib_session => @parser.zlib_session})
57520c4 @igrigorik simple EM spdy server example
authored
13 h = {'Content-Type' => 'text/plain', 'status' => '200 OK', 'version' => 'HTTP/1.1'}
d0cd597 @carsonmcdonald Reworked compression so that it spans the life of a session.
carsonmcdonald authored
14 sr.create({:stream_id => stream_id, :headers => h})
57520c4 @igrigorik simple EM spdy server example
authored
15 send_data sr.to_binary_s
16
17 p [:SPDY, :sent, :SYN_REPLY]
18
19 d = SPDY::Protocol::Data::Frame.new
d0cd597 @carsonmcdonald Reworked compression so that it spans the life of a session.
carsonmcdonald authored
20 d.create(:stream_id => stream_id, :data => "This is SPDY.")
57520c4 @igrigorik simple EM spdy server example
authored
21 send_data d.to_binary_s
22
23 p [:SPDY, :sent, :DATA]
24
25 d = SPDY::Protocol::Data::Frame.new
d0cd597 @carsonmcdonald Reworked compression so that it spans the life of a session.
carsonmcdonald authored
26 d.create(:stream_id => stream_id, :flags => 1)
57520c4 @igrigorik simple EM spdy server example
authored
27 send_data d.to_binary_s
28
29 p [:SPDY, :sent, :DATA_FIN]
30 end
31
32 end
33
34 def receive_data(data)
cfef951 @igrigorik update example to new API, drop TLS
authored
35 p [:received, data]
57520c4 @igrigorik simple EM spdy server example
authored
36 @parser << data
37 end
38
39 def unbind
40 p [:SPDY, :connection_closed]
d0cd597 @carsonmcdonald Reworked compression so that it spans the life of a session.
carsonmcdonald authored
41 @parser.zlib_session.reset
57520c4 @igrigorik simple EM spdy server example
authored
42 end
43 end
44
45 EM.run do
c967ba8 @igrigorik update example server
authored
46 EM.start_server '0.0.0.0', 10000, SPDYHandler
57520c4 @igrigorik simple EM spdy server example
authored
47 end
48
c967ba8 @igrigorik update example server
authored
49 # (1) start the SPDY eventmachine server
50 # > ruby spdy_server.rb
51 #
52 # (2) start Chrome and force it to use SPDY over SSL.. on OSX:
53 # > /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --use-spdy=ssl
54 #
2619272 @eee-c Add missing zero on the port number in the example.
eee-c authored
55 # (3) visit https://localhost:10000/
Something went wrong with that request. Please try again.