Skip to content

Fix ResolveURL using default proxy #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/launcher/url_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package launcher
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -124,6 +125,9 @@ func ResolveURL(u string) (string, error) {
return "", err
}
defer func() { _ = res.Body.Close() }()
if res.StatusCode != 200 {
return "", fmt.Errorf("failed to get the browser version, status: %d", res.StatusCode)
}

data, err := io.ReadAll(res.Body)
utils.E(err)
Expand Down
39 changes: 39 additions & 0 deletions lib/launcher/url_parser_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package launcher

import (
"crypto/tls"
"net/http"
"net/url"
"strings"
"testing"
)

func TestResolveURLUsingDefaultProxy(t *testing.T) {
setProxy("http://127.0.0.1:7890")

u, err := ResolveURL("37712")
if err != nil {
t.Fatal(err)
}

if strings.Contains(u, "<nil>") || strings.Contains(u, `%3Cnil%3E`) {
t.Fatal(u)
}

t.Log(u)
}

func setProxy(proxy string) error {
proxyURL, err := url.Parse(proxy)
if err != nil {
return err
}

// set http default client to use proxy
http.DefaultClient.Transport = &http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}

return nil
}