Port PR https://github.com/dotcloud/docker-registry/pull/357 here