# File lib/faye/websocket/hybi_parser/handshake.rb, line 55
        def valid?
          data = WebSocket.encode(@buffer)

          response = Net::HTTPResponse.read_new(Net::BufferedIO.new(StringIO.new(data)))
          return false unless response.code.to_i == 101

          upgrade    = response['Upgrade']
          connection = response['Connection']
          protocol   = response['Sec-WebSocket-Protocol']

          @protocol = @protocols && @protocols.include?(protocol) ?
                      protocol :
                      nil

          upgrade and upgrade =~ /^websocket$/i and
          connection and connection.split(/\s*,\s*/).include?('Upgrade') and
          ((!@protocols and !protocol) or @protocol) and
          response['Sec-WebSocket-Accept'] == @accept
        end