HTTPretty icon indicating copy to clipboard operation
HTTPretty copied to clipboard

Support for different content encodings or raw bodies

Open oschwald opened this issue 12 years ago • 2 comments

As far as I can tell, there is no way to test with a response where the content encoding is gzip or some other compression. The body gets mangled in the process, probably by the utf8 handling.

oschwald avatar May 06 '13 17:05 oschwald

:+1: for gzip encoding

rgbkrk avatar Jan 03 '14 21:01 rgbkrk

mean that?

gzip:

import StringIO
import gzip

import httpretty

plain_file = StringIO.StringIO()
gzip_file = gzip.GzipFile(fileobj=plain_file, mode='w')
gzip_file.writelines('I am gzip')
gzip_file.close()
gzip_str = plain_file.getvalue()
plain_file.close()

httpretty.register_uri(
    httpretty.GET, 'http://www.example.com/', status=200, body=gzip_str,
    forcing_headers={'content-encoding': 'gzip'}
)

deflate:

import zlib

import httpretty

deflate_str = zlib.compress('I am deflate')
httpretty.register_uri(
    httpretty.GET, 'http://www.example.com/', status=200, body=deflate_str,
    forcing_headers={'content-encoding': 'deflate'}
)

akun avatar May 19 '14 09:05 akun