Permalink
Browse files

Merge pull request #145 from bkoski/master

Add a 200 OK response at /healthcheck
  • Loading branch information...
2 parents b814291 + 33c5ce6 commit f705cf3589840a1dd892d13a56b4dd08a4e2e8e6 @igrigorik committed on GitHub Apr 28, 2017
Showing with 20 additions and 1 deletion.
  1. +20 −1 lib/em-websocket/connection.rb
@@ -110,7 +110,9 @@ def unbind
end
def dispatch(data)
- if data.match(/\A<policy-file-request\s*\/>/)
+ if data.match(%r|^GET /healthcheck|)
+ send_healthcheck_response
+ elsif data.match(/\A<policy-file-request\s*\/>/)
send_flash_cross_domain_file
else
@handshake ||= begin
@@ -139,6 +141,23 @@ def dispatch(data)
end
end
+ def send_healthcheck_response
+ debug [:healthcheck, 'OK']
+
+ healthcheck_res = ["HTTP/1.1 200 OK"]
+ healthcheck_res << "Content-Type: text/plain"
+ healthcheck_res << "Content-Length: 2"
+
+ healthcheck_res = healthcheck_res.join("\r\n") + "\r\n\r\nOK"
+
+ send_data healthcheck_res
+
+ # handle the healthcheck request transparently
+ # no need to notify the user about this connection
+ @onclose = nil
+ close_connection_after_writing
+ end
+
def send_flash_cross_domain_file
file = '<?xml version="1.0"?><cross-domain-policy><allow-access-from domain="*" to-ports="*"/></cross-domain-policy>'
debug [:cross_domain, file]

0 comments on commit f705cf3

Please sign in to comment.