Skip to content

Commit 6eca452

Browse files
committed
missgin http requests for proxy
1 parent 634c613 commit 6eca452

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,8 @@ is `data/repo-archive` and the default of `MINIO_BASE_PATH` is `repo-archive/`.
10271027
## Proxy (`proxy`)
10281028

10291029
- `PROXY_ENABLED`: **false**: Enable the proxy if true, all requests to external via HTTP will be affected, if false, no proxy will be used even environment http_proxy/https_proxy
1030-
- `PROXY_URL`: ****: Proxy server URL, support http://, https//, socks://, blank will follow environment http_proxy/https_proxy
1031-
- `PROXY_HOSTS`: ****: Comma separated list of host names requiring proxy. Glob patterns (*) are accepted; use ** to match all hosts.
1030+
- `PROXY_URL`: **\<empty\>**: Proxy server URL, support http://, https//, socks://, blank will follow environment http_proxy/https_proxy
1031+
- `PROXY_HOSTS`: **\<empty\>**: Comma separated list of host names requiring proxy. Glob patterns (*) are accepted; use ** to match all hosts.
10321032

10331033
i.e.
10341034
```ini

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ Repository archive 的存储配置。 如果 `STORAGE_TYPE` 为空,则此配
401401
## Proxy (`proxy`)
402402

403403
- `PROXY_ENABLED`: **false**: 是否启用全局代理。如果为否,则不使用代理,环境变量中的代理也不使用
404-
- `PROXY_URL`: ****: 代理服务器地址,支持 http://, https//, socks://,为空则不启用代理而使用环境变量中的 http_proxy/https_proxy
405-
- `PROXY_HOSTS`: ****: 逗号分隔的多个需要代理的网址,支持 * 号匹配符号, ** 表示匹配所有网站
404+
- `PROXY_URL`: **\<empty\>**: 代理服务器地址,支持 http://, https//, socks://,为空则不启用代理而使用环境变量中的 http_proxy/https_proxy
405+
- `PROXY_HOSTS`: **\<empty\>**: 逗号分隔的多个需要代理的网址,支持 * 号匹配符号, ** 表示匹配所有网站
406406

407407
i.e.
408408
```ini

modules/migrations/gitea_downloader.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ func (g *GiteaDownloader) convertGiteaRelease(rel *gitea_sdk.Release) *base.Rele
275275
Created: rel.CreatedAt,
276276
}
277277

278+
httpClient := &http.Client{
279+
Transport: &http.Transport{
280+
TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Migrations.SkipTLSVerify},
281+
Proxy: proxy.Proxy(),
282+
},
283+
}
284+
278285
for _, asset := range rel.Attachments {
279286
size := int(asset.Size)
280287
dlCount := int(asset.DownloadCount)
@@ -291,7 +298,11 @@ func (g *GiteaDownloader) convertGiteaRelease(rel *gitea_sdk.Release) *base.Rele
291298
return nil, err
292299
}
293300
// FIXME: for a private download?
294-
resp, err := http.Get(asset.DownloadURL)
301+
req, err := http.NewRequest("GET", asset.DownloadURL, nil)
302+
if err != nil {
303+
return nil, err
304+
}
305+
resp, err := httpClient.Do(req)
295306
if err != nil {
296307
return nil, err
297308
}

modules/migrations/github.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package migrations
77

88
import (
99
"context"
10+
"crypto/tls"
1011
"fmt"
1112
"io"
1213
"net/http"
@@ -18,6 +19,7 @@ import (
1819
"code.gitea.io/gitea/modules/log"
1920
"code.gitea.io/gitea/modules/migrations/base"
2021
"code.gitea.io/gitea/modules/proxy"
22+
"code.gitea.io/gitea/modules/setting"
2123
"code.gitea.io/gitea/modules/structs"
2224
"code.gitea.io/gitea/modules/util"
2325

@@ -270,6 +272,13 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
270272
r.Published = rel.PublishedAt.Time
271273
}
272274

275+
httpClient := &http.Client{
276+
Transport: &http.Transport{
277+
TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Migrations.SkipTLSVerify},
278+
Proxy: proxy.Proxy(),
279+
},
280+
}
281+
273282
for _, asset := range rel.Assets {
274283
var assetID = *asset.ID // Don't optimize this, for closure we need a local variable
275284
r.Assets = append(r.Assets, &base.ReleaseAsset{
@@ -296,7 +305,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
296305
if err != nil {
297306
return nil, err
298307
}
299-
resp, err := http.DefaultClient.Do(req)
308+
resp, err := httpClient.Do(req)
300309
err1 := g.RefreshRate()
301310
if err1 != nil {
302311
log.Error("g.client.RateLimits: %s", err1)

modules/migrations/gitlab.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ func (g *GitlabDownloader) convertGitlabRelease(rel *gitlab.Release) *base.Relea
303303
PublisherName: rel.Author.Username,
304304
}
305305

306+
httpClient := &http.Client{
307+
Transport: &http.Transport{
308+
TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Migrations.SkipTLSVerify},
309+
Proxy: proxy.Proxy(),
310+
},
311+
}
312+
306313
for k, asset := range rel.Assets.Links {
307314
r.Assets = append(r.Assets, &base.ReleaseAsset{
308315
ID: int64(asset.ID),
@@ -321,8 +328,7 @@ func (g *GitlabDownloader) convertGitlabRelease(rel *gitlab.Release) *base.Relea
321328
return nil, err
322329
}
323330
req = req.WithContext(g.ctx)
324-
325-
resp, err := http.DefaultClient.Do(req)
331+
resp, err := httpClient.Do(req)
326332
if err != nil {
327333
return nil, err
328334
}

0 commit comments

Comments
 (0)