Class: SockJS::Transports::IFrame
- Defined in:
- lib/sockjs/transports/iframe.rb
Constant Summary collapse
- BODY =
<<-EOB.freeze <!DOCTYPE html> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script> document.domain = document.domain; _sockjs_onload = function(){SockJS.bootstrap_iframe();}; </script> <script src="{{ sockjs_url }}"></script> </head> <body> <h2>Don't panic!</h2> <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p> </body> </html> EOB
Instance Attribute Summary
Attributes inherited from Endpoint
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
37 38 39 |
# File 'lib/sockjs/transports/iframe.rb', line 37 def body @body ||= BODY.gsub("{{ sockjs_url }}", [:sockjs_url]) end |
#digest ⇒ Object
41 42 43 |
# File 'lib/sockjs/transports/iframe.rb', line 41 def digest @digest ||= Digest::MD5.new end |
#etag ⇒ Object
45 46 47 |
# File 'lib/sockjs/transports/iframe.rb', line 45 def etag '"' + digest.hexdigest(body) + '"' end |
#handle_request(request) ⇒ Object
Handler.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sockjs/transports/iframe.rb', line 50 def handle_request(request) if request.fresh?(etag) SockJS.debug "Content hasn't been modified." 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 |
# File 'lib/sockjs/transports/iframe.rb', line 30 def setup_response(request, response) response.status = 200 response.set_header("ETag", self.etag) response.set_cache_control response end |