Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use CONNECT command for 1.1, 1.2 #348

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions stomp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def send_frame(self, cmd, headers=None, body=''):
:param dict headers: a map of headers to include in the frame
:param body: the content of the message
"""
if cmd != CMD_CONNECT:
if cmd not in [CMD_CONNECT, CMD_STOMP]:
if headers is None:
headers = {}
self._escape_headers(headers)
Expand Down Expand Up @@ -306,17 +306,19 @@ def commit(self, transaction=None, headers=None, **keyword_headers):
headers[HDR_TRANSACTION] = transaction
self.send_frame(CMD_COMMIT, headers)

def connect(self, username=None, passcode=None, wait=False, headers=None, **keyword_headers):
def connect(self, username=None, passcode=None, wait=False, headers=None,
with_connect_command=False, **keyword_headers):
"""
Start a connection.

:param str username: the username to connect with
:param str passcode: the password used to authenticate with
:param bool wait: if True, wait for the connection to be established/acknowledged
:param dict headers: a map of any additional headers the broker requires
:param with_connect_command: if True, use CONNECT command instead of STOMP
:param keyword_headers: any additional headers the broker requires
"""
cmd = CMD_STOMP
cmd = CMD_CONNECT if with_connect_command else CMD_STOMP
headers = utils.merge_headers([headers, keyword_headers])
headers[HDR_ACCEPT_VERSION] = self.version

Expand Down Expand Up @@ -487,17 +489,19 @@ def nack(self, id, transaction=None, receipt=None, **keyword_headers):
headers[HDR_RECEIPT] = receipt
self.send_frame(CMD_NACK, headers)

def connect(self, username=None, passcode=None, wait=False, headers=None, **keyword_headers):
def connect(self, username=None, passcode=None, wait=False, headers=None,
with_connect_command=False, **keyword_headers):
"""
Send a STOMP CONNECT frame. Differs from 1.0 and 1.1 versions in that the HOST header is enforced.

:param str username: optionally specify the login user
:param str passcode: optionally specify the user password
:param bool wait: wait for the connection to complete before returning
:param dict headers: a map of any additional headers to send with the subscription
:param with_connect_command: if True, use CONNECT command instead of STOMP
:param keyword_headers: any additional headers to send with the subscription
"""
cmd = CMD_STOMP
cmd = CMD_CONNECT if with_connect_command else CMD_STOMP
headers = utils.merge_headers([headers, keyword_headers])
headers[HDR_ACCEPT_VERSION] = self.version
headers[HDR_HOST] = self.transport.current_host_and_port[0]
Expand Down