Dont base64-encode bodies
- Send deflate content-encoding
This commit is contained in:
parent
13fd2410b6
commit
a76101f1fe
|
@ -8,7 +8,6 @@ raven.base
|
|||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import base64
|
||||
import zlib
|
||||
import logging
|
||||
import os
|
||||
|
@ -626,6 +625,7 @@ class Client(object):
|
|||
headers = {
|
||||
'User-Agent': client_string,
|
||||
'X-Sentry-Auth': auth_header,
|
||||
'Content-Encoding': self.get_content_encoding(),
|
||||
'Content-Type': 'application/octet-stream',
|
||||
}
|
||||
|
||||
|
@ -636,17 +636,20 @@ class Client(object):
|
|||
**kwargs
|
||||
)
|
||||
|
||||
def get_content_encoding(self):
|
||||
return 'deflate'
|
||||
|
||||
def encode(self, data):
|
||||
"""
|
||||
Serializes ``data`` into a raw string.
|
||||
"""
|
||||
return base64.b64encode(zlib.compress(json.dumps(data).encode('utf8')))
|
||||
return zlib.compress(json.dumps(data).encode('utf8'))
|
||||
|
||||
def decode(self, data):
|
||||
"""
|
||||
Unserializes a string, ``data``.
|
||||
"""
|
||||
return json.loads(zlib.decompress(base64.b64decode(data)).decode('utf8'))
|
||||
return json.loads(zlib.decompress(data).decode('utf8'))
|
||||
|
||||
def captureMessage(self, message, **kwargs):
|
||||
"""
|
||||
|
|
|
@ -175,10 +175,11 @@ class ClientTest(TestCase):
|
|||
})
|
||||
send_remote.assert_called_once_with(
|
||||
url='http://example.com/api/1/store/',
|
||||
data=six.b('eJyrVkrLz1eyUlBKSixSqgUAIJgEVA=='),
|
||||
data=client.encode({'foo': 'bar'}),
|
||||
headers={
|
||||
'User-Agent': 'raven-python/%s' % (raven.VERSION,),
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Encoding': client.get_content_encoding(),
|
||||
'X-Sentry-Auth': (
|
||||
'Sentry sentry_timestamp=1328055286.51, '
|
||||
'sentry_client=raven-python/%s, sentry_version=6, '
|
||||
|
@ -199,11 +200,12 @@ class ClientTest(TestCase):
|
|||
})
|
||||
send_remote.assert_called_once_with(
|
||||
url='http://example.com/api/1/store/',
|
||||
data=six.b('eJyrVkrLz1eyUlBKSixSqgUAIJgEVA=='),
|
||||
data=client.encode({'foo': 'bar'}),
|
||||
headers={
|
||||
'User-Agent': 'raven-python/%s' % (raven.VERSION,),
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'X-Sentry-Auth': 'foo'
|
||||
'Content-Encoding': client.get_content_encoding(),
|
||||
'X-Sentry-Auth': 'foo',
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ from raven.utils import json
|
|||
import datetime
|
||||
import calendar
|
||||
import pytz
|
||||
import base64
|
||||
import zlib
|
||||
|
||||
|
||||
|
@ -58,8 +57,8 @@ class TransportTest(TestCase):
|
|||
|
||||
mock_cls = c._transport_cache['mock://some_username:some_password@localhost:8143/1'].get_transport()
|
||||
|
||||
expected_message = zlib.decompress(base64.b64decode(c.encode(data)))
|
||||
actual_message = zlib.decompress(base64.b64decode(mock_cls._data))
|
||||
expected_message = zlib.decompress(c.encode(data))
|
||||
actual_message = zlib.decompress(mock_cls._data)
|
||||
|
||||
# These loads()/dumps() pairs order the dict keys before comparing the string.
|
||||
# See GH504
|
||||
|
|
Loading…
Reference in New Issue