Class: SockJS::Transports::IFrame

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/sockjs/transports/iframe.rb

Constant Summary collapse

BODY =
"<!DOCTYPE html>\n<html>\n<head>\n  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n  <script>\n    document.domain = document.domain;\n    _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n  </script>\n  <script src=\"{{ sockjs_url }}\"></script>\n</head>\n<body>\n  <h2>Don't panic!</h2>\n  <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n</body>\n</html>\n".freeze

Instance Attribute Summary

Attributes inherited from Endpoint

#connection, #http_origin, #options, #remote_addr

Attributes included from Endpoint::ClassMethods

#method, #prefix

Instance Method Summary collapse

Methods inherited from Endpoint

#build_error_response, #build_response, #call, #empty_string, #error_content_type, #format_frame, #handle, #handle_http_error, #initialize, #inspect, #response_class

Methods included from Endpoint::ClassMethods

#add_route, #add_routes, #endpoints, #register, #route_conditions, #routing_prefix

Constructor Details

This class inherits a constructor from SockJS::Endpoint

Instance Method Details

#bodyObject



38
39
40
# File 'lib/sockjs/transports/iframe.rb', line 38

def body
  @body ||= BODY.gsub("{{ sockjs_url }}", options[:sockjs_url])
end

#digestObject



42
43
44
# File 'lib/sockjs/transports/iframe.rb', line 42

def digest
  @digest ||= Digest::MD5.new
end

#etagObject



46
47
48
# File 'lib/sockjs/transports/iframe.rb', line 46

def etag
  '"' + digest.hexdigest(body) + '"'
end

#handle_request(request) ⇒ Object

Handler.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sockjs/transports/iframe.rb', line 51

def handle_request(request)
  if request.fresh?(etag)
    response = build_response(request)
    response.status = 304
    response.finish
    return response
  else
    SockJS.debug "Deferring to Transport"
    response = build_response(request)
    response.set_content_type(:html)
    response.write(body)
    response.finish
    return response
  end
end

#setup_response(request, response) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/sockjs/transports/iframe.rb', line 30

def setup_response(request, response)
  SockJS.debug("body: #{@body.inspect}")
  response.status = 200
  response.set_header("ETag", self.etag)
  response.set_cache_control
  response
end