oisinmulvihill/stomper — pull request #4 by dvarrazzo (2014-01-30 18:42:37+00:00)
Title: Fixed newline prepended to messages without transaction id

Sending a message without tx id inserts an extra newline which is then parsed as beginning of the message.

I have found this patch in some source of ours: credit goes to a colleague of mine. As well as the blame if his interpretation of the protocol is wrong :)

Example:

>>> c.send(stomper.subscribe('/foo'))
>>> c.send(stomper.send('/foo', 'bar'))
>OUT 'SEND\ndestination: /foo\n\n\nbar\x00\n'
>IN {'body': '\nbar', 'headers': {'message-id': '/foo_1', 'destination': '/foo'}, 'cmd': 'MESSAGE'}

the body has an extra '\n' in front of the message, whereas

>>> c.send(stomper.send('/foo', 'bar', 'asdf'))
>OUT 'SEND\ndestination: /foo\ntransaction: asdf\n\nbar\x00\n'
>IN {'body': 'bar', 'headers': {'message-id': '/foo_2', 'destination': '/foo', 'transaction': 'asdf'}, 'cmd': 'MESSAGE'}

no newline here.