Prevent loop with var overshadowing

Incase of a 3xx redirect the var was being overshowed and ever changed
causing an infinite loop.

Fixes #9480

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Refactor put image function's redirect loop

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Merge pull request #9604 from crosbymichael/registry-fruit-loops

Prevent infinite loop with var overshadowing