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

_recorder.record captures header 'content-encoding: gzip' but does not return gzip content on replay #724

Open
chriskauffman37 opened this issue Jun 24, 2024 · 1 comment
Labels

Comments

@chriskauffman37
Copy link

Describe the bug

headers has been added to the recording file which may include content-encoding. When a recording with content-encoding: gzip is replayed an error is received:

urllib3.exceptions.DecodeError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))

Additional context

No response

Version of responses

0.25.3

Steps to Reproduce

# Recording code

@_recorder.record(file_path="out.yaml")
def record():
    # call lookup API
- response:
    auto_calculate_content_length: false
    body: '[{"first_name":true,"last_name":true,"email":false,"phone_number":false,"custom_id":true,"user_id":"abc123","status":{"code":"ACTIVE","description":"The
      user is fully active with all features enabled. Further restrictions may apply
      for some features."},"employers":[{"id":"abc123","sso_required":false}]}]'
    content_type: text/plain
    headers:
      API-Version: '1'
      X-Dep-Next: T-0.8.4
      X-Download-Options: noopen
      X-Permitted-Cross-Domain-Policies: none
      X-Request-Id: f8903c30-4fb2-4b30-95b1-b20e0fdfb515
      X-Runtime: '0.129368'
      apigw-requestid: Z0iA3ibpIAMEaxg=
      cache-control: max-age=0, private, must-revalidate
      content-encoding: gzip
      etag: W/"2b965752b6adbb3fd7467a489ad314b0"
      referrer-policy: strict-origin-when-cross-origin
      vary: Accept-Encoding, Origin
      x-content-type-options: nosniff
      x-frame-options: SAMEORIGIN
      x-xss-protection: '0'
    method: GET
    status: 200
    url: https://api.com/v1/users/lookup?custom_id=060419806551&last_name=Murphy&first_name=Lucy
# Test code

@responses.activate
def test_lookup_api():
    responses._add_from_file(file_path="out.yaml")

    lookup = # call lookup API
    assert lookup["first_name"] == True

Expected Result

Pass

Actual Result

urllib3.exceptions.DecodeError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))

@markstory
Copy link
Member

Storing gzip data in yaml files feels gross. Removing the content-encoding header and storing the response body as str/bytes seems more human-friendly to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Waiting for: Product Owner
Development

No branches or pull requests

2 participants