Skip to content

Commit 0f23b9e

Browse files
broferekludovicfelixfontein
authored
Force Content-type header to application/json if is_pre740 is false (#10832)
* Force Content-type header to application/json if is_pre740 is false * Remove response variable from fail_json module * Add a missing blank line to match pep8 requirement * Add changelog fragment of issue #10796 * Rename fragment section * Improve fragment readability Co-authored-by: Felix Fontein <[email protected]> --------- Co-authored-by: ludovic <[email protected]> Co-authored-by: Felix Fontein <[email protected]>
1 parent b865bf5 commit 0f23b9e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- rocketchat - fix message delivery in Rocket Chat >= 7.5.3 by forcing ``Content-Type`` header to ``application/json`` instead of the default ``application/x-www-form-urlencoded`` (https://github.com/ansible-collections/community.general/issues/10796, https://github.com/ansible-collections/community.general/pull/10796).

plugins/modules/rocketchat.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,17 @@ def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon
202202
return payload
203203

204204

205-
def do_notify_rocketchat(module, domain, token, protocol, payload):
205+
def do_notify_rocketchat(module, domain, token, protocol, payload, is_pre740):
206206

207207
if token.count('/') < 1:
208208
module.fail_json(msg="Invalid Token specified, provide a valid token")
209209

210210
rocketchat_incoming_webhook = ROCKETCHAT_INCOMING_WEBHOOK % (protocol, domain, token)
211211

212-
response, info = fetch_url(module, rocketchat_incoming_webhook, data=payload)
212+
headers = None
213+
if not is_pre740:
214+
headers = {'Content-type': 'application/json'}
215+
response, info = fetch_url(module, rocketchat_incoming_webhook, data=payload, headers=headers)
213216
if info['status'] != 200:
214217
module.fail_json(msg="failed to send message, return status=%s" % str(info['status']))
215218

@@ -256,7 +259,7 @@ def main():
256259
is_pre740 = True
257260

258261
payload = build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, is_pre740)
259-
do_notify_rocketchat(module, domain, token, protocol, payload)
262+
do_notify_rocketchat(module, domain, token, protocol, payload, is_pre740)
260263

261264
module.exit_json(msg="OK")
262265

0 commit comments

Comments
 (0)