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

Mirroring fixes #396

Merged
merged 2 commits into from
May 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docker_registry/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
@app.route('/_ping')
@app.route('/v1/_ping')
def ping():
return toolkit.response(headers={
'X-Docker-Registry-Standalone': cfg.standalone is not False
})
headers = {'X-Docker-Registry-Standalone': cfg.standalone is not False}
if cfg.mirroring:
headers['X-Docker-Registry-Standalone'] = 'mirror'
return toolkit.response(headers=headers)


@app.route('/')
Expand Down
30 changes: 17 additions & 13 deletions docker_registry/lib/mirroring.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def is_mirror():
return bool(cfg.get('mirroring', False))


def _response_headers(base):
headers = {}
if not base:
return headers
for k, v in base.iteritems():
if k.lower() == 'content-encoding':
continue
headers[k.lower()] = v
logger.warn(headers)
return headers


def lookup_source(path, stream=False, source=None):
if not source:
cfg = config.load()
Expand Down Expand Up @@ -77,10 +89,7 @@ def wrapper(namespace, repository, *args, **kwargs):
if not source_resp:
return resp

headers = source_resp.headers
if 'Content-Encoding' in headers:
del headers['Content-Encoding']

headers = _response_headers(source_resp.headers)
return toolkit.response(data=source_resp.content, headers=headers,
raw=True)

Expand All @@ -105,10 +114,7 @@ def wrapper(namespace, repository, *args, **kwargs):
if not source_resp:
return resp
data = source_resp.content
headers = source_resp.headers
if 'Content-Encoding' in headers:
del headers['Content-Encoding']

headers = _response_headers(source_resp.headers)
cache.redis_conn.setex('{0}:{1}'.format(
cache.cache_prefix, tag_path
), tags_cache_ttl, data)
Expand Down Expand Up @@ -142,11 +148,9 @@ def wrapper(*args, **kwargs):

store = storage.load()

headers = source_resp.headers
if 'Content-Encoding' in headers:
del headers['Content-Encoding']
if index_route and 'X-Docker-Endpoints' in headers:
headers['X-Docker-Endpoints'] = toolkit.get_endpoints()
headers = _response_headers(source_resp.headers)
if index_route and 'x-docker-endpoints' in headers:
headers['x-docker-endpoints'] = toolkit.get_endpoints()

if not stream:
logger.debug('JSON data found on source, writing response')
Expand Down
2 changes: 0 additions & 2 deletions docker_registry/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ def iterate(self, chunk_size=-1):
if chunk_size == -1:
chunk_size = 1024
for chunk in self._fp.iter_content(chunk_size):
logger.debug('Read %d bytes' % len(chunk))
for handler in self.handlers:
handler(chunk)
yield chunk
else:
chunk = self._fp.read(chunk_size)
while chunk:
logger.debug('Read %d bytes' % len(chunk))
for handler in self.handlers:
handler(chunk)
yield chunk
Expand Down