github.com/drone/runner-go@v1.12.0/environ/proxy.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package environ 6 7 import ( 8 "strings" 9 ) 10 11 // Proxy returns the http_proxy variables. 12 func Proxy() map[string]string { 13 environ := map[string]string{} 14 if value := envAnyCase("no_proxy"); value != "" { 15 environ["no_proxy"] = value 16 environ["NO_PROXY"] = value 17 } 18 if value := envAnyCase("http_proxy"); value != "" { 19 environ["http_proxy"] = value 20 environ["HTTP_PROXY"] = value 21 } 22 if value := envAnyCase("https_proxy"); value != "" { 23 environ["https_proxy"] = value 24 environ["HTTPS_PROXY"] = value 25 } 26 if value := envAnyCase("all_proxy"); value != "" { 27 environ["all_proxy"] = value 28 environ["ALL_PROXY"] = value 29 } 30 return environ 31 } 32 33 // helper function returns the environment variable value 34 // using a case-insenstive environment name. 35 func envAnyCase(name string) (value string) { 36 name = strings.ToUpper(name) 37 if value := getenv(name); value != "" { 38 return value 39 } 40 name = strings.ToLower(name) 41 if value := getenv(name); value != "" { 42 return value 43 } 44 return 45 }