File tree Expand file tree Collapse file tree 1 file changed +16
-11
lines changed
Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -800,18 +800,10 @@ def initialize s
800800 def handshake port , path
801801 key = SecureRandom . hex ( 11 )
802802 @sock . print "GET #{ path } HTTP/1.1\r \n Host: 127.0.0.1:#{ port } \r \n Connection: Upgrade\r \n Upgrade: websocket\r \n Sec-WebSocket-Version: 13\r \n Sec-WebSocket-Key: #{ key } ==\r \n \r \n "
803- res = nil
804- loop do
805- res = @sock . readpartial 4092
806- break unless res . match? ( /out|input/ )
807- end
803+ server_key = get_server_key
808804
809- if res . match ( /^Sec-WebSocket-Accept: (.*)\r \n / )
810- correct_key = Base64 . strict_encode64 Digest ::SHA1 . digest "#{ key } ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
811- raise "The Sec-WebSocket-Accept value: #{ $1} is not valid" unless $1 == correct_key
812- else
813- raise "Unknown response: #{ res } "
814- end
805+ correct_key = Base64 . strict_encode64 Digest ::SHA1 . digest "#{ key } ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
806+ raise "The Sec-WebSocket-Accept value: #{ $1} is not valid" unless server_key == correct_key
815807 end
816808
817809 def send msg
@@ -882,6 +874,19 @@ def send_close_connection
882874 def close
883875 @sock . close
884876 end
877+
878+ private
879+
880+ def get_server_key
881+ Timeout . timeout ( ProtocolTestCase ::TIMEOUT_SEC ) do
882+ loop do
883+ res = @sock . readpartial 4092
884+ if res . match ( /^Sec-WebSocket-Accept: (.*)\r \n / )
885+ return $1
886+ end
887+ end
888+ end
889+ end
885890 end
886891
887892 # When constant variables are referred from modules, they have to be defined outside the class.
You can’t perform that action at this time.
0 commit comments