From upstream: https://github.com/docker/distribution/commit/ec6566c02b9c452d8e465ffa41c1c20117228917