From 3342d7bbbf147e65a41dcbd3509152c1962617b5 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 5 May 2015 15:09:51 +0200 Subject: [PATCH] Parse heart-beat header only if present According to the STOMP spec, the `heart-beat` header is OPTIONAL and a missing header must be treated as `heart-beat:0,0`. Prior to this changen the STOMP implementation would try to directly `.split()` this header value without checking for its existence first. This commit checks for the existence of the heart-beat header and uses the default value `"0,0"` if it's not set. See: https://stomp.github.io/stomp-specification-1.2.html#Heart-beating --- src/stomp.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stomp.coffee b/src/stomp.coffee index 69788a9..d217faf 100644 --- a/src/stomp.coffee +++ b/src/stomp.coffee @@ -189,7 +189,8 @@ class Client # heart-beat header received from the server looks like: # # heart-beat: sx, sy - [serverOutgoing, serverIncoming] = (parseInt(v) for v in headers['heart-beat'].split(",")) + [serverOutgoing, serverIncoming] = + if headers['heart-beat']? then (parseInt(v) for v in headers['heart-beat'].split(",")) else [0, 0] unless @heartbeat.outgoing == 0 or serverIncoming == 0 ttl = Math.max(@heartbeat.outgoing, serverIncoming)