# File lib/faye/websocket/hybi_parser.rb, line 61
      def handshake_response
        sec_key = @socket.env['HTTP_SEC_WEBSOCKET_KEY']
        return '' unless String === sec_key

        accept    = Base64.encode64(Digest::SHA1.digest(sec_key + Handshake::GUID)).strip
        protos    = @socket.env['HTTP_SEC_WEBSOCKET_PROTOCOL']
        supported = @protocols
        proto     = nil

        headers = [
          "HTTP/1.1 101 Switching Protocols",
          "Upgrade: websocket",
          "Connection: Upgrade",
          "Sec-WebSocket-Accept: #{accept}"
        ]

        if protos and supported
          protos = protos.split(/\s*,\s*/) if String === protos
          proto = protos.find { |p| supported.include?(p) }
          if proto
            @protocol = proto
            headers << "Sec-WebSocket-Protocol: #{proto}"
          end
        end

        (headers + ['','']).join("\r\n")
      end