Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit ee9a2bd

Browse files
committed
Better headers handling in mirroring, removed some superfluous logging
1 parent 3faf029 commit ee9a2bd

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

docker_registry/lib/mirroring.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ def is_mirror():
1818
return bool(cfg.get('mirroring', False))
1919

2020

21+
def _response_headers(base):
22+
headers = {}
23+
if not base:
24+
return headers
25+
for k, v in base.iteritems():
26+
if k.lower() == 'content-encoding':
27+
continue
28+
headers[k.lower()] = v
29+
logger.warn(headers)
30+
return headers
31+
32+
2133
def lookup_source(path, stream=False, source=None):
2234
if not source:
2335
cfg = config.load()
@@ -77,10 +89,7 @@ def wrapper(namespace, repository, *args, **kwargs):
7789
if not source_resp:
7890
return resp
7991

80-
headers = source_resp.headers
81-
if 'Content-Encoding' in headers:
82-
del headers['Content-Encoding']
83-
92+
headers = _response_headers(source_resp.headers)
8493
return toolkit.response(data=source_resp.content, headers=headers,
8594
raw=True)
8695

@@ -105,10 +114,7 @@ def wrapper(namespace, repository, *args, **kwargs):
105114
if not source_resp:
106115
return resp
107116
data = source_resp.content
108-
headers = source_resp.headers
109-
if 'Content-Encoding' in headers:
110-
del headers['Content-Encoding']
111-
117+
headers = _response_headers(source_resp.headers)
112118
cache.redis_conn.setex('{0}:{1}'.format(
113119
cache.cache_prefix, tag_path
114120
), tags_cache_ttl, data)
@@ -142,11 +148,9 @@ def wrapper(*args, **kwargs):
142148

143149
store = storage.load()
144150

145-
headers = source_resp.headers
146-
if 'Content-Encoding' in headers:
147-
del headers['Content-Encoding']
148-
if index_route and 'X-Docker-Endpoints' in headers:
149-
headers['X-Docker-Endpoints'] = toolkit.get_endpoints()
151+
headers = _response_headers(source_resp.headers)
152+
if index_route and 'x-docker-endpoints' in headers:
153+
headers['x-docker-endpoints'] = toolkit.get_endpoints()
150154

151155
if not stream:
152156
logger.debug('JSON data found on source, writing response')

docker_registry/toolkit.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ def iterate(self, chunk_size=-1):
4848
if chunk_size == -1:
4949
chunk_size = 1024
5050
for chunk in self._fp.iter_content(chunk_size):
51-
logger.debug('Read %d bytes' % len(chunk))
5251
for handler in self.handlers:
5352
handler(chunk)
5453
yield chunk
5554
else:
5655
chunk = self._fp.read(chunk_size)
5756
while chunk:
58-
logger.debug('Read %d bytes' % len(chunk))
5957
for handler in self.handlers:
6058
handler(chunk)
6159
yield chunk

0 commit comments

Comments
 (0)