Class: SockJS::Transports::IFrame
- 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
Instance Method Summary collapse
- #body ⇒ Object
- #digest ⇒ Object
- #etag ⇒ Object
-
#handle_request(request) ⇒ Object
Handler.
- #setup_response(request, response) ⇒ Object
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
#body ⇒ Object
38 39 40 |
# File 'lib/sockjs/transports/iframe.rb', line 38 def body @body ||= BODY.gsub("{{ sockjs_url }}", [:sockjs_url]) end |
#digest ⇒ Object
42 43 44 |
# File 'lib/sockjs/transports/iframe.rb', line 42 def digest @digest ||= Digest::MD5.new end |
#etag ⇒ Object
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 |