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

Commit 397297f

Browse files
committed
Merge pull request #387 from dotcloud/mirroring_fixes
Mirroring fixes
2 parents be5849c + ea6e568 commit 397297f

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

docker_registry/index.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from . import storage
1313
from . import toolkit
14-
from .lib import config
1514
from .lib import mirroring
1615
from .lib import signals
1716

@@ -28,18 +27,8 @@
2827
"""
2928

3029

31-
def get_endpoints(cfg=None):
32-
if not cfg:
33-
cfg = config.load()
34-
registry_endpoints = cfg.registry_endpoints
35-
if not registry_endpoints:
36-
#registry_endpoints = socket.gethostname()
37-
registry_endpoints = flask.request.environ['HTTP_HOST']
38-
return registry_endpoints
39-
40-
4130
def generate_headers(namespace, repository, access):
42-
registry_endpoints = get_endpoints()
31+
registry_endpoints = toolkit.get_endpoints()
4332
# The token generated will be invalid against a real Index behind.
4433
token = 'Token signature={0},repository="{1}/{2}",access={3}'.format(
4534
toolkit.gen_random_string(), namespace, repository, access)

docker_registry/lib/mirroring.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ def wrapper(namespace, repository, *args, **kwargs):
7878
)
7979
if not source_resp:
8080
return resp
81-
return toolkit.response(data=source_resp.content,
82-
headers=source_resp.headers, raw=True)
81+
82+
headers = source_resp.headers
83+
if 'Content-Encoding' in headers:
84+
del headers['Content-Encoding']
85+
86+
return toolkit.response(data=source_resp.content, headers=headers,
87+
raw=True)
8388

8489
store = storage.load()
8590
request_path = flask.request.path
@@ -102,10 +107,14 @@ def wrapper(namespace, repository, *args, **kwargs):
102107
if not source_resp:
103108
return resp
104109
data = source_resp.content
110+
headers = source_resp.headers
111+
if 'Content-Encoding' in headers:
112+
del headers['Content-Encoding']
113+
105114
cache.redis_conn.setex('{0}:{1}'.format(
106115
cache.cache_prefix, tag_path
107116
), tags_cache_ttl, data)
108-
return toolkit.response(data=data, headers=source_resp.headers,
117+
return toolkit.response(data=data, headers=headers,
109118
raw=True)
110119
return wrapper
111120

@@ -138,6 +147,8 @@ def wrapper(*args, **kwargs):
138147
headers = source_resp.headers
139148
if 'Content-Encoding' in headers:
140149
del headers['Content-Encoding']
150+
if index_route and 'X-Docker-Endpoints' in headers:
151+
headers['X-Docker-Endpoints'] = toolkit.get_endpoints()
141152

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

docker_registry/toolkit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,13 @@ def get_repository():
303303
if len(parts) < 2:
304304
return ('library', parts[0])
305305
return (parts[0], parts[1])
306+
307+
308+
def get_endpoints(cfg=None):
309+
if not cfg:
310+
cfg = config.load()
311+
registry_endpoints = cfg.registry_endpoints
312+
if not registry_endpoints:
313+
#registry_endpoints = socket.gethostname()
314+
registry_endpoints = flask.request.environ['HTTP_HOST']
315+
return registry_endpoints

0 commit comments

Comments
 (0)