Skip to content

Commit c04af81

Browse files
committed
handle non-ascii headers
1 parent fb0a2f9 commit c04af81

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Modules/_librabbitmq/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ PyDict_ToAMQTable(amqp_connection_state_t conn, PyObject *src, amqp_pool_t *pool
320320
is_unicode = PyUnicode_Check(dvalue);
321321
if (is_unicode || PyBytes_Check(dvalue)) {
322322
if (is_unicode) {
323-
if ((dvalue = PyUnicode_AsASCIIString(dvalue)) == NULL)
323+
if ((dvalue = PyUnicode_AsEncodedString(dvalue, "utf-8", "strict")) == NULL)
324324
goto error;
325325
}
326326
AMQTable_SetStringValue(&dst,

tests/test_functional.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding: utf-8
12
from __future__ import absolute_import
23

34
from six.moves import xrange
@@ -30,6 +31,14 @@ def test_send_message(self):
3031
self.assertGreater(self.channel.queue_purge(TEST_QUEUE), 2)
3132
self.channel.basic_publish(message, TEST_QUEUE, TEST_QUEUE)
3233
self.channel.basic_publish(message, TEST_QUEUE, TEST_QUEUE)
34+
35+
def test_nonascii_headers(self):
36+
message = Message(
37+
channel=self.channel,
38+
body='the quick brown fox jumps over the lazy dog',
39+
properties=dict(content_type='application/json',
40+
content_encoding='utf-8',
41+
headers={'key': '¯\_(ツ)_/¯'}))
3342
self.channel.basic_publish(message, TEST_QUEUE, TEST_QUEUE)
3443

3544
def _queue_declare(self):

0 commit comments

Comments
 (0)