Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

use http.DefaultClient (#2530)

Michael Yang897b213468d8
diff --git a/api/client.go b/api/client.go
index 4fe8668a3..36019206a 100644
--- a/api/client.go
+++ b/api/client.go
@@ -21,7 +21,7 @@ import (
type Client struct {
base *url.URL
- http http.Client
+ http *http.Client
}
func checkError(resp *http.Response, body []byte) error {
@@ -66,30 +66,13 @@ func ClientFromEnvironment() (*Client, error) {
}
}
- client := Client{
+ return &Client{
base: &url.URL{
Scheme: scheme,
Host: net.JoinHostPort(host, port),
},
- }
-
- mockRequest, err := http.NewRequest(http.MethodHead, client.base.String(), nil)
- if err != nil {
- return nil, err
- }
-
- proxyURL, err := http.ProxyFromEnvironment(mockRequest)
- if err != nil {
- return nil, err
- }
-
- client.http = http.Client{
- Transport: &http.Transport{
- Proxy: http.ProxyURL(proxyURL),
- },
- }
-
- return &client, nil
+ http: http.DefaultClient,
+ }, nil
}
func (c *Client) do(ctx context.Context, method, path string, reqData, respData any) error {
diff --git a/app/lifecycle/updater.go b/app/lifecycle/updater.go
index da69c327b..e0d232999 100644
--- a/app/lifecycle/updater.go
+++ b/app/lifecycle/updater.go
@@ -34,20 +34,6 @@ type UpdateResponse struct {
UpdateVersion string `json:"version"`
}
-func getClient(req *http.Request) http.Client {
- proxyURL, err := http.ProxyFromEnvironment(req)
- if err != nil {
- slog.Warn(fmt.Sprintf("failed to handle proxy: %s", err))
- return http.Client{}
- }
-
- return http.Client{
- Transport: &http.Transport{
- Proxy: http.ProxyURL(proxyURL),
- },
- }
-}
-
func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
var updateResp UpdateResponse
@@ -83,10 +69,9 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
}
req.Header.Set("Authorization", signature)
req.Header.Set("User-Agent", fmt.Sprintf("ollama/%s (%s %s) Go/%s", version.Version, runtime.GOARCH, runtime.GOOS, runtime.Version()))
- client := getClient(req)
slog.Debug("checking for available update", "requestURL", requestURL)
- resp, err := client.Do(req)
+ resp, err := http.DefaultClient.Do(req)
if err != nil {
slog.Warn(fmt.Sprintf("failed to check for update: %s", err))
return false, updateResp
@@ -119,8 +104,8 @@ func DownloadNewRelease(ctx context.Context, updateResp UpdateResponse) error {
if err != nil {
return err
}
- client := getClient(req)
- resp, err := client.Do(req)
+
+ resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("error checking update: %w", err)
}
@@ -151,7 +136,7 @@ func DownloadNewRelease(ctx context.Context, updateResp UpdateResponse) error {
cleanupOldDownloads()
req.Method = http.MethodGet
- resp, err = client.Do(req)
+ resp, err = http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("error checking update: %w", err)
}
diff --git a/server/images.go b/server/images.go
index 391809cbd..a000c5c57 100644
--- a/server/images.go
+++ b/server/images.go
@@ -1103,18 +1103,7 @@ func makeRequest(ctx context.Context, method string, requestURL *url.URL, header
req.ContentLength = contentLength
}
- proxyURL, err := http.ProxyFromEnvironment(req)
- if err != nil {
- return nil, err
- }
-
- client := http.Client{
- Transport: &http.Transport{
- Proxy: http.ProxyURL(proxyURL),
- },
- }
-
- resp, err := client.Do(req)
+ resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}