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

Commit 1e860ce

Browse files
committed
Merge pull request #396 from dotcloud/mirroring_fixes
Mirroring fixes
2 parents 639be74 + ee9a2bd commit 1e860ce

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

docker_registry/app.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
@app.route('/_ping')
2727
@app.route('/v1/_ping')
2828
def ping():
29-
return toolkit.response(headers={
30-
'X-Docker-Registry-Standalone': cfg.standalone is not False
31-
})
29+
headers = {'X-Docker-Registry-Standalone': cfg.standalone is not False}
30+
if cfg.mirroring:
31+
headers['X-Docker-Registry-Standalone'] = 'mirror'
32+
return toolkit.response(headers=headers)
3233

3334

3435
@app.route('/')

docker_registry/lib/mirroring.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ def is_mirror():
2020
return bool(cfg.get('mirroring', False))
2121

2222

23+
def _response_headers(base):
24+
headers = {}
25+
if not base:
26+
return headers
27+
for k, v in base.iteritems():
28+
if k.lower() == 'content-encoding':
29+
continue
30+
headers[k.lower()] = v
31+
logger.warn(headers)
32+
return headers
33+
34+
2335
def lookup_source(path, stream=False, source=None):
2436
if not source:
2537
cfg = config.load()
@@ -79,10 +91,7 @@ def wrapper(namespace, repository, *args, **kwargs):
7991
if not source_resp:
8092
return resp
8193

82-
headers = source_resp.headers
83-
if 'Content-Encoding' in headers:
84-
del headers['Content-Encoding']
85-
94+
headers = _response_headers(source_resp.headers)
8695
return toolkit.response(data=source_resp.content, headers=headers,
8796
raw=True)
8897

@@ -107,10 +116,7 @@ def wrapper(namespace, repository, *args, **kwargs):
107116
if not source_resp:
108117
return resp
109118
data = source_resp.content
110-
headers = source_resp.headers
111-
if 'Content-Encoding' in headers:
112-
del headers['Content-Encoding']
113-
119+
headers = _response_headers(source_resp.headers)
114120
cache.redis_conn.setex('{0}:{1}'.format(
115121
cache.cache_prefix, tag_path
116122
), tags_cache_ttl, data)
@@ -144,11 +150,9 @@ def wrapper(*args, **kwargs):
144150

145151
store = storage.load()
146152

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

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

docker_registry/toolkit.py

-2
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@ def iterate(self, chunk_size=-1):
5252
if chunk_size == -1:
5353
chunk_size = 1024
5454
for chunk in self._fp.iter_content(chunk_size):
55-
logger.debug('Read %d bytes' % len(chunk))
5655
for handler in self.handlers:
5756
handler(chunk)
5857
yield chunk
5958
else:
6059
chunk = self._fp.read(chunk_size)
6160
while chunk:
62-
logger.debug('Read %d bytes' % len(chunk))
6361
for handler in self.handlers:
6462
handler(chunk)
6563
yield chunk

0 commit comments

Comments
 (0)