docker / docker/docker-py

Handle custom headers in post request

Open
#3,003 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

Issue

As of now, options such as stream, or timeout are not passed to the call to the docker API.

Cause

These options are circulated through the headers of the http query to the docker API. But recent modifications of the requests library state that adding custom headers to an http query should be handled by the code inheriting from "". See:
https://github.com/psf/requests/blob/786255613bd92f87c9c8f066c4271aab1b9eeaad/requests/adapters.py#L401-L413

Solution

Therefore, I think that a add_headers methods should be added to the UnixHTTPAdapter.

Here is my (particularly ugly) workaround:

        def add_headers(self, request, **kwargs):
            from requests.structures import CaseInsensitiveDict
            new_head = dict(request.headers)
            for key, val in kwargs.items():
                new_head[key] = str(val)
            request.headers = CaseInsensitiveDict(new_head)

        cli = docker.APIClient()
        if hasattr(cli, '_transport_adapter'):
            cli._transport_adapter.add_headers = add_headers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue points to UnixHTTPAdapter and APIClient; start by tracing how APIClient POST requests reach the adapter and compare the referenced requests adapters.py behavior. Done means custom headers and options such as stream and timeout reach the Docker API through the request path.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.