Skip to content

Commit

Permalink
Auto-send content-length when message body is present
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Aug 3, 2015
1 parent 573ad5d commit 8c9c616
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
4 changes: 0 additions & 4 deletions stomp/backward2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def encode(char_data):
return char_data


def hasbyte(byte, byte_data):
return chr(byte) in byte_data


def pack(pieces):
return ''.join(pieces)

Expand Down
5 changes: 0 additions & 5 deletions stomp/backward3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ def encode(char_data):
raise TypeError('message should be a string or bytes')


def hasbyte(byte, byte_data):
assert type(byte) is int and 0 <= byte and byte < 2**8
return bytes([byte]) in byte_data


def pack(pieces):
encoded_pieces = (encode(piece) for piece in pieces)
return b''.join(encoded_pieces)
Expand Down
8 changes: 4 additions & 4 deletions stomp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from stomp.exception import ConnectFailedException
from stomp.listener import *
from stomp.backward import encode, hasbyte
from stomp.backward import encode
from stomp.constants import *
import stomp.utils as utils

Expand Down Expand Up @@ -83,8 +83,8 @@ def send(self, destination, body, content_type=None, headers={}, **keyword_heade
if content_type:
headers[HDR_CONTENT_TYPE] = content_type
body = encode(body)
#if HDR_CONTENT_LENGTH not in headers:
# headers[HDR_CONTENT_LENGTH] = len(body)
if body and HDR_CONTENT_LENGTH not in headers:
headers[HDR_CONTENT_LENGTH] = len(body)
self.send_frame(CMD_SEND, headers, body)

def subscribe(self, destination, id=None, ack='auto', headers={}, **keyword_headers):
Expand Down Expand Up @@ -200,7 +200,7 @@ def send(self, destination, body, content_type=None, headers={}, **keyword_heade
if content_type:
headers[HDR_CONTENT_TYPE] = content_type
body = encode(body)
if HDR_CONTENT_LENGTH not in headers and hasbyte(0, body):
if body and HDR_CONTENT_LENGTH not in headers:
headers[HDR_CONTENT_LENGTH] = len(body)
self.send_frame(CMD_SEND, headers, body)

Expand Down

0 comments on commit 8c9c616

Please sign in to comment.