Project

Profile

Help

Refactor #3303

Updated by mihai.ibanescu@gmail.com about 4 years ago

Docker engines typically present more than one Accept: header (usually three).

While they are three different lines in the HTTP header, they typically get combined as a single value, comma-separated.

Crane has a bunch of if/then/else logic that looks like:

<pre>
accept_headers = request.headers.get('Accept')
schema2_mediatype = 'application/vnd.docker.distribution.manifest.v2+json'
manifest_list_mediatype = 'application/vnd.docker.distribution.manifest.list.v2+json'
if manifest_list_mediatype in accept_headers ...:
...
</pre>

That is essentially the equivalent of evaluating:

<pre>
"val1" in "val1, val2, val3"
</pre>

and boils down to string matching.

I find found it dangerous, because "val" in "val1, val2, val3" is also True.

It just so happens that the Docker engine is civilized enough to present the right values.

A much better solution would be something like:

<pre>
accept_headers = accept_headers.split(",") if accept_headers else []
accept_headers = set(x.strip() for x in accept_headers)
</pre>

Back