     for k in ["jid", "sid", "rid"] when connection[k]?
       sessionStorage[key2cache k] = connection[k]
 
-    for k in ["host", "port", "path"] when connection_options[k]?
+    for k in ["host", "port", "path", "protocol"] when connection_options[k]?
       sessionStorage[key2cache k] = connection_options[k]
 
 clearData = -> sessionStorage?.clear()


    # case 1
    if opt.host and opt.port and opt.path
      return "http://#{ opt.host }:#{ opt.port }/#{ opt.path }"

    # case 2
    if opt.host and opt.port and not opt.path
      return "http://#{ opt.host }:#{ opt.port }/#{ DEFAULT_PATH }"

    # case 3
    if opt.host and not opt.port and opt.path
      return "http://#{ opt.host }/#{ opt.path }"

    # case 4
    if opt.host and not opt.port and not opt.path
      return "http://#{ opt.host }/#{ DEFAULT_PATH }"

    # case 5
    if not opt.host and opt.port and opt.path
      return "http://#{ domain }:#{ opt.port }/#{ opt.path }"

    # case 6
    if not opt.host and opt.port and not opt.path
      return "http://#{ domain }:#{ opt.port }/#{ DEFAULT_PATH }"

    # case 7
    if not opt.host and not opt.port and opt.path
      return "http://#{ domain }/#{ opt.path }"

    # case 8
    if not opt.host and not opt.port and not opt.path
      return "http://#{ domain }/#{ DEFAULT_PATH }"

  # fallback
  "http://#{ domain }/#{ DEFAULT_PATH }"

create_connection_obj = ->

  new Strophe.Connection get_bosh_url
    path:     connection_options.path
    host:     connection_options.host
    port:     connection_options.port
    protocol: connection_options.protocol

key2cache   = (k) -> "#{CACHE_PREFIX}#{k}"

