blob: 87bd5b1776dde18f79b67710b8893d19a2d82bbc [file] [log] [blame]
David K. Bainbridge528b3182017-01-23 08:51:59 -08001// Copyright 2016 Canonical Ltd.
2// Licensed under the LGPLv3, see LICENCE file for details.
3
4//+build !go1.7
5
6package utils
7
8import (
9 "fmt"
10 "net"
11 "net/http"
12)
13
14// installHTTPDialShim patches the default HTTP transport so
15// that it fails when an attempt is made to dial a non-local
16// host.
17func installHTTPDialShim(t *http.Transport) {
18 t.Dial = func(network, addr string) (net.Conn, error) {
19 if !OutgoingAccessAllowed && !isLocalAddr(addr) {
20 return nil, fmt.Errorf("access to address %q not allowed", addr)
21 }
22 return net.Dial(network, addr)
23 }
24}