Skip to content

Commit

Permalink
fix proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpaulus committed Aug 5, 2024
1 parent 7cc64c8 commit 348b457
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ios/imagemounter/imagedownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"runtime"
"strings"
"time"

"github.com/Masterminds/semver"
"github.com/danielpaulus/go-ios/ios"
Expand Down Expand Up @@ -247,8 +248,12 @@ func validateBaseDirAndLookForImage(baseDir string, imageToFind string) (string,
// write as it downloads and not load the whole file into memory.
// PS: Taken from golangcode.com
func downloadFile(filepath string, url string) error {
c := &http.Client{
Timeout: 2 * time.Minute,
Transport: http.DefaultTransport,
}
// Get the data
resp, err := http.Get(url)
resp, err := c.Get(url)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion ios/imagemounter/tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type tssClient struct {

func newTssClient() tssClient {
c := &http.Client{
Timeout: 1 * time.Minute,
Timeout: 1 * time.Minute,
Transport: http.DefaultTransport,
}

return tssClient{
Expand Down
3 changes: 2 additions & 1 deletion ios/mobileactivation/albert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const (
)

var netClient = &http.Client{
Timeout: time.Second * 5,
Timeout: time.Second * 5,
Transport: http.DefaultTransport,
}

func sendHandshakeRequest(body io.Reader) (http.Header, io.ReadCloser, error) {
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -145,6 +147,8 @@ Options:
> connect a device and open Xcode
--rsd-port=<port> Port of remote service discovery on the device through the tunnel
> This parameter is similar to '--address' and can be obtained by the same log filter
--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.
> A simple format like: "http://PROXY_LOGIN:PROXY_PASS@proxyIp:proxyPort" works. Otherwise use the HTTP_PROXY system env var.
The commands work as following:
The default output of all commands is JSON. Should you prefer human readable outout, specify the --nojson option with your command.
Expand Down Expand Up @@ -291,6 +295,15 @@ The commands work as following:
printVersion()
return
}
proxyUrl, _ := arguments.String("--proxyurl")
if proxyUrl == "" {
proxyUrl = os.Getenv("HTTP_PROXY")
}
if proxyUrl != "" {
parsedUrl, err := url.Parse(proxyUrl)
exitIfError("failed parsing proxy url", err)
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(parsedUrl)}
}

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

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

0 comments on commit 348b457

Please sign in to comment.