Factor out proxy fetching code so that it can be called from more than one place.

Jira issue: WP-1318