Skip to content

Commit b51df98

Browse files
authored
fix proxy support (danielpaulus#448)
In Golang only the default http client uses the system wide env var. this led to some weird behavior with half of go-ios supporting it and the other half not so much. I changed it to use the default transport always.
1 parent 7cc64c8 commit b51df98

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

ios/imagemounter/imagedownloader.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010
"runtime"
1111
"strings"
12+
"time"
1213

1314
"github.com/Masterminds/semver"
1415
"github.com/danielpaulus/go-ios/ios"
@@ -247,8 +248,12 @@ func validateBaseDirAndLookForImage(baseDir string, imageToFind string) (string,
247248
// write as it downloads and not load the whole file into memory.
248249
// PS: Taken from golangcode.com
249250
func downloadFile(filepath string, url string) error {
251+
c := &http.Client{
252+
Timeout: 2 * time.Minute,
253+
Transport: http.DefaultTransport,
254+
}
250255
// Get the data
251-
resp, err := http.Get(url)
256+
resp, err := c.Get(url)
252257
if err != nil {
253258
return err
254259
}

ios/imagemounter/tss.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ type tssClient struct {
2020

2121
func newTssClient() tssClient {
2222
c := &http.Client{
23-
Timeout: 1 * time.Minute,
23+
Timeout: 1 * time.Minute,
24+
Transport: http.DefaultTransport,
2425
}
2526

2627
return tssClient{

ios/mobileactivation/albert.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const (
1515
)
1616

1717
var netClient = &http.Client{
18-
Timeout: time.Second * 5,
18+
Timeout: time.Second * 5,
19+
Transport: http.DefaultTransport,
1920
}
2021

2122
func sendHandshakeRequest(body io.Reader) (http.Header, io.ReadCloser, error) {

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"encoding/json"
88
"fmt"
99
"io"
10+
"net/http"
11+
"net/url"
1012
"os"
1113
"os/signal"
1214
"path"
@@ -145,6 +147,8 @@ Options:
145147
> connect a device and open Xcode
146148
--rsd-port=<port> Port of remote service discovery on the device through the tunnel
147149
> This parameter is similar to '--address' and can be obtained by the same log filter
150+
--proxyurl=<url> Set this if you want go-ios to use a http proxy for outgoing requests, like for downloading images or contacting Apple during device activation.
151+
> A simple format like: "http://PROXY_LOGIN:PROXY_PASS@proxyIp:proxyPort" works. Otherwise use the HTTP_PROXY system env var.
148152
149153
The commands work as following:
150154
The default output of all commands is JSON. Should you prefer human readable outout, specify the --nojson option with your command.
@@ -291,6 +295,15 @@ The commands work as following:
291295
printVersion()
292296
return
293297
}
298+
proxyUrl, _ := arguments.String("--proxyurl")
299+
if proxyUrl == "" {
300+
proxyUrl = os.Getenv("HTTP_PROXY")
301+
}
302+
if proxyUrl != "" {
303+
parsedUrl, err := url.Parse(proxyUrl)
304+
exitIfError("failed parsing proxy url", err)
305+
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(parsedUrl)}
306+
}
294307

295308
b, _ := arguments.Bool("listen")
296309
if b {
@@ -1115,6 +1128,7 @@ func imageCommand1(device ios.DeviceEntry, arguments docopt.Opts) bool {
11151128
if err != nil {
11161129
log.WithFields(log.Fields{"basedir": basedir, "udid": device.Properties.SerialNumber, "err": err}).
11171130
Error("failed downloading image")
1131+
return false
11181132
}
11191133

11201134
log.WithFields(log.Fields{"basedir": basedir, "udid": device.Properties.SerialNumber}).Info("success downloaded image")

0 commit comments

Comments
 (0)