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: use a case-insensitive HTTP headers check #728

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Jul 10, 2024

  1. recorder: use a case-insensitive HTTP headers check

    _recorder._remove_default_headers() does a case-sensitive check for
    HTTP header field names are case insensitive. The result is that for
    example, a lower-case 'content-type' field will not be removed. Later,
    when _add_from_file tries to load the data using RequestsMock.add(), a
    RuntimeError exception will be raised when it finds the 'content_type'
    kwarg was passed and 'content-type' is in the 'headers' kwargs.
    
    Fix this by simply having _remove_default_headers() do a
    case-insensitive check.
    
    Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
    ptalbert committed Jul 10, 2024
    Configuration menu
    Copy the full SHA
    7b9b8cf View commit details
    Browse the repository at this point in the history
  2. recorder: set content_type for Response in Recorder._on_request

    Recorder._on_request does not set the content_type parameter when
    creating a new Response instance. When content_type is not set the
    Response.__init__ will always set the value to "text/plain". This means
    the recording file is always written with that content type and when
    responses are replayed they may not have their original content-type
    header value.
    
    For example, the python-gitlab package expects the response header
    content type to be 'application/json' but this information is in the
    recording and playing it back will fail.
    
    Fix this by having _on_request() pass in the content_type of the
    requests_response.header.
    
    Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
    ptalbert committed Jul 10, 2024
    Configuration menu
    Copy the full SHA
    8d2bfe7 View commit details
    Browse the repository at this point in the history