File tree 3 files changed +33
-3
lines changed 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1
1
Juan Antonio Martín Lucas <dev@jaml.pro>
2
2
Aurora Nockert <aurora@aventine.se>
3
+ Thomas Morgan <tm@iprog.com>
Original file line number Diff line number Diff line change @@ -20,9 +20,10 @@ class UpgradeRequest < ::Protocol::HTTP::Request
20
20
include ::Protocol ::WebSocket ::Headers
21
21
22
22
class Wrapper
23
- def initialize ( response )
23
+ def initialize ( response , verified : )
24
24
@response = response
25
25
@stream = nil
26
+ @verified = verified
26
27
end
27
28
28
29
def close
@@ -32,7 +33,7 @@ def close
32
33
attr_accessor :response
33
34
34
35
def stream?
35
- @response . status == 101
36
+ @response . status == 101 && @verified
36
37
end
37
38
38
39
def status
@@ -74,7 +75,7 @@ def call(connection)
74
75
end
75
76
end
76
77
77
- return Wrapper . new ( response )
78
+ return Wrapper . new ( response , verified : !! accept_digest )
78
79
end
79
80
end
80
81
end
Original file line number Diff line number Diff line change 110
110
with 'http/1' do
111
111
let ( :protocol ) { Async ::HTTP ::Protocol ::HTTP1 }
112
112
it_behaves_like ClientExamples
113
+
114
+ with 'invalid sec-websocket-accept header' do
115
+ let ( :app ) do
116
+ Protocol ::HTTP ::Middleware . for do |request |
117
+ Protocol ::HTTP ::Response [ 101 , { 'sec-websocket-accept' => 'wrong-digest' } , [ ] ]
118
+ end
119
+ end
120
+
121
+ it 'raises an error' do
122
+ expect do
123
+ Async ::WebSocket ::Client . connect ( client_endpoint ) { }
124
+ end . to raise_exception ( Async ::WebSocket ::ProtocolError , message : be =~ /Invalid accept digest/ )
125
+ end
126
+ end
127
+
128
+ with 'missing sec-websocket-accept header' do
129
+ let ( :app ) do
130
+ Protocol ::HTTP ::Middleware . for do |request |
131
+ Protocol ::HTTP ::Response [ 101 , { } , [ ] ]
132
+ end
133
+ end
134
+
135
+ it 'raises an error' do
136
+ expect do
137
+ Async ::WebSocket ::Client . connect ( client_endpoint ) { }
138
+ end . to raise_exception ( Async ::WebSocket ::ProtocolError , message : be =~ /Failed to negotiate connection/ )
139
+ end
140
+ end
113
141
end
114
142
115
143
with 'http/2' do
You can’t perform that action at this time.
0 commit comments