diff --git a/agent/app/service/app.go b/agent/app/service/app.go index bb9bbeee6..cf70fa9de 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -26,8 +26,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/1Panel-dev/1Panel/agent/utils/docker" "github.com/1Panel-dev/1Panel/agent/utils/files" - http2 "github.com/1Panel-dev/1Panel/agent/utils/http" - httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http" + "github.com/1Panel-dev/1Panel/agent/utils/req_helper" "github.com/1Panel-dev/1Panel/agent/utils/xpack" "gopkg.in/yaml.v3" ) @@ -260,7 +259,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response. if appDetailDTO.DockerCompose == "" { filename := filepath.Base(appDetailDTO.DownloadUrl) dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(appDetailDTO.DownloadUrl, filename), "docker-compose.yml") - statusCode, composeRes, err := httpUtil.HandleGet(dockerComposeUrl, http.MethodGet, constant.TimeOut20s) + statusCode, composeRes, err := req_helper.HandleRequest(dockerComposeUrl, http.MethodGet, constant.TimeOut20s) if err != nil { return appDetailDTO, buserr.WithDetail("ErrGetCompose", err.Error(), err) } @@ -773,7 +772,7 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) { } versionUrl := fmt.Sprintf("%s/%s/1panel.json.version.txt", global.CONF.System.AppRepo, global.CONF.System.Mode) - _, versionRes, err := http2.HandleGet(versionUrl, http.MethodGet, constant.TimeOut20s) + _, versionRes, err := req_helper.HandleRequest(versionUrl, http.MethodGet, constant.TimeOut20s) if err != nil { return nil, err } @@ -936,7 +935,6 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) { oldAppIds = append(oldAppIds, old.ID) } - transport := xpack.LoadRequestTransport() baseRemoteUrl := fmt.Sprintf("%s/%s/1panel", global.CONF.System.AppRepo, global.CONF.System.Mode) appsMap := getApps(oldApps, list.Apps, setting.SystemVersion, t) @@ -944,7 +942,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) { t.LogStart(i18n.GetMsgByKey("SyncAppDetail")) for _, l := range list.Apps { app := appsMap[l.AppProperty.Key] - _, iconRes, err := httpUtil.HandleGetWithTransport(l.Icon, http.MethodGet, transport, constant.TimeOut20s) + _, iconRes, err := req_helper.HandleRequest(l.Icon, http.MethodGet, constant.TimeOut20s) if err != nil { return err } @@ -977,7 +975,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) { } if _, ok := InitTypes[app.Type]; ok { dockerComposeUrl := fmt.Sprintf("%s/%s", versionUrl, "docker-compose.yml") - _, composeRes, err := httpUtil.HandleGetWithTransport(dockerComposeUrl, http.MethodGet, transport, constant.TimeOut20s) + _, composeRes, err := req_helper.HandleRequest(dockerComposeUrl, http.MethodGet, constant.TimeOut20s) if err != nil { return err } diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index a47c72e41..69ed78ac6 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -15,7 +15,7 @@ import ( "strings" "github.com/1Panel-dev/1Panel/agent/utils/files" - httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http" + "github.com/1Panel-dev/1Panel/agent/utils/req_helper" "github.com/docker/docker/api/types" "gopkg.in/yaml.v3" @@ -553,7 +553,7 @@ func (a *AppInstallService) GetUpdateVersions(req request.AppUpdateVersion) ([]d if req.UpdateVersion != "" && req.UpdateVersion == detail.Version && detail.DockerCompose == "" && !app.IsLocalApp() { filename := filepath.Base(detail.DownloadUrl) dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(detail.DownloadUrl, filename), "docker-compose.yml") - statusCode, composeRes, err := httpUtil.HandleGet(dockerComposeUrl, http.MethodGet, constant.TimeOut20s) + statusCode, composeRes, err := req_helper.HandleRequest(dockerComposeUrl, http.MethodGet, constant.TimeOut20s) if err != nil { return versions, err } diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index a6f344020..e249d5923 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -26,7 +26,7 @@ import ( "github.com/docker/docker/api/types" - httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http" + "github.com/1Panel-dev/1Panel/agent/utils/req_helper" "github.com/docker/docker/api/types/container" "github.com/1Panel-dev/1Panel/agent/utils/cmd" @@ -1758,5 +1758,5 @@ func RequestDownloadCallBack(downloadCallBackUrl string) { if downloadCallBackUrl == "" { return } - _, _, _ = httpUtil.HandleGet(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s) + _, _, _ = req_helper.HandleRequest(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s) } diff --git a/agent/app/service/website_ssl.go b/agent/app/service/website_ssl.go index 8da25b154..a7d064ec2 100644 --- a/agent/app/service/website_ssl.go +++ b/agent/app/service/website_ssl.go @@ -6,7 +6,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - http2 "github.com/1Panel-dev/1Panel/agent/utils/http" "log" "os" "path" @@ -25,6 +24,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/utils/cmd" "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/1Panel-dev/1Panel/agent/utils/files" + "github.com/1Panel-dev/1Panel/agent/utils/req_helper" "github.com/1Panel-dev/1Panel/agent/utils/ssl" "github.com/go-acme/lego/v4/certcrypto" legoLogger "github.com/go-acme/lego/v4/log" @@ -205,7 +205,7 @@ func reloadSystemSSL(websiteSSL *model.WebsiteSSL, logger *log.Logger) { logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error()) return } - if err := http2.PostLocalCore("/core/settings/ssl/reload"); err != nil { + if err := req_helper.PostLocalCore("/core/settings/ssl/reload"); err != nil { logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error()) return } diff --git a/agent/utils/files/file_op.go b/agent/utils/files/file_op.go index 2e7f1275c..ac2ed4d22 100644 --- a/agent/utils/files/file_op.go +++ b/agent/utils/files/file_op.go @@ -21,7 +21,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/utils/cmd" - http2 "github.com/1Panel-dev/1Panel/agent/utils/http" + "github.com/1Panel-dev/1Panel/agent/utils/req_helper" cZip "github.com/klauspost/compress/zip" "golang.org/x/text/encoding/simplifiedchinese" "golang.org/x/text/transform" @@ -315,7 +315,7 @@ func (f FileOp) DownloadFileWithProcess(url, dst, key string, ignoreCertificate } func (f FileOp) DownloadFile(url, dst string) error { - resp, err := http2.GetHttpRes(url) + resp, err := req_helper.HandleGet(url) if err != nil { return err } @@ -334,7 +334,7 @@ func (f FileOp) DownloadFile(url, dst string) error { } func (f FileOp) DownloadFileWithProxy(url, dst string) error { - _, resp, err := http2.HandleGet(url, http.MethodGet, constant.TimeOut5m) + _, resp, err := req_helper.HandleRequest(url, http.MethodGet, constant.TimeOut5m) if err != nil { return err } diff --git a/agent/utils/http/get.go b/agent/utils/http/get.go deleted file mode 100644 index 692c648cb..000000000 --- a/agent/utils/http/get.go +++ /dev/null @@ -1,42 +0,0 @@ -package http - -import ( - "context" - "errors" - "net/http" - "strings" - "time" - - "github.com/1Panel-dev/1Panel/agent/buserr" - "github.com/1Panel-dev/1Panel/agent/utils/xpack" -) - -func GetHttpRes(url string) (*http.Response, error) { - client := &http.Client{ - Timeout: time.Second * 300, - } - transport := xpack.LoadRequestTransport() - client.Transport = transport - - req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil) - if err != nil { - return nil, buserr.WithMap("ErrCreateHttpClient", map[string]interface{}{"err": err.Error()}, err) - } - - resp, err := client.Do(req) - if err != nil { - if errors.Is(err, context.DeadlineExceeded) { - return nil, buserr.WithMap("ErrHttpReqTimeOut", map[string]interface{}{"err": err.Error()}, err) - } else { - if strings.Contains(err.Error(), "no such host") { - return nil, buserr.New("ErrNoSuchHost") - } - return nil, buserr.WithMap("ErrHttpReqFailed", map[string]interface{}{"err": err.Error()}, err) - } - } - if resp.StatusCode == 404 { - return nil, buserr.New("ErrHttpReqNotFound") - } - - return resp, nil -} diff --git a/agent/utils/http/request.go b/agent/utils/http/request.go deleted file mode 100644 index 3d64853d6..000000000 --- a/agent/utils/http/request.go +++ /dev/null @@ -1,49 +0,0 @@ -package http - -import ( - "context" - "errors" - "io" - "net/http" - "time" - - "github.com/1Panel-dev/1Panel/agent/global" - "github.com/1Panel-dev/1Panel/agent/utils/xpack" -) - -func HandleGet(url, method string, timeout int) (int, []byte, error) { - transport := xpack.LoadRequestTransport() - return HandleGetWithTransport(url, method, transport, timeout) -} - -func HandleGetWithTransport(url, method string, transport *http.Transport, timeout int) (int, []byte, error) { - defer func() { - if r := recover(); r != nil { - global.LOG.Errorf("handle request failed, error message: %v", r) - return - } - }() - - client := http.Client{Timeout: time.Duration(timeout) * time.Second, Transport: transport} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) - defer cancel() - request, err := http.NewRequestWithContext(ctx, method, url, nil) - if err != nil { - return 0, nil, err - } - request.Header.Set("Content-Type", "application/json") - resp, err := client.Do(request) - if err != nil { - return 0, nil, err - } - if resp.StatusCode != http.StatusOK { - return 0, nil, errors.New(resp.Status) - } - body, err := io.ReadAll(resp.Body) - if err != nil { - return 0, nil, err - } - defer resp.Body.Close() - - return resp.StatusCode, body, nil -} diff --git a/agent/utils/http/core.go b/agent/utils/req_helper/core.go similarity index 97% rename from agent/utils/http/core.go rename to agent/utils/req_helper/core.go index 87eb6350f..8177226cc 100644 --- a/agent/utils/http/core.go +++ b/agent/utils/req_helper/core.go @@ -1,10 +1,11 @@ -package http +package req_helper import ( "bytes" "fmt" - "github.com/1Panel-dev/1Panel/agent/app/repo" "net/http" + + "github.com/1Panel-dev/1Panel/agent/app/repo" ) func PostLocalCore(url string) error { diff --git a/agent/utils/req_helper/request.go b/agent/utils/req_helper/request.go new file mode 100644 index 000000000..f0b23c08f --- /dev/null +++ b/agent/utils/req_helper/request.go @@ -0,0 +1,90 @@ +package req_helper + +import ( + "context" + "crypto/tls" + "errors" + "io" + "net" + "net/http" + "strings" + "time" + + "github.com/1Panel-dev/1Panel/agent/buserr" + "github.com/1Panel-dev/1Panel/agent/global" +) + +func HandleGet(url string) (*http.Response, error) { + client := &http.Client{ + Timeout: time.Second * 300, + } + client.Transport = loadRequestTransport() + + req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil) + if err != nil { + return nil, buserr.WithMap("ErrCreateHttpClient", map[string]interface{}{"err": err.Error()}, err) + } + + resp, err := client.Do(req) + if err != nil { + if errors.Is(err, context.DeadlineExceeded) { + return nil, buserr.WithMap("ErrHttpReqTimeOut", map[string]interface{}{"err": err.Error()}, err) + } else { + if strings.Contains(err.Error(), "no such host") { + return nil, buserr.New("ErrNoSuchHost") + } + return nil, buserr.WithMap("ErrHttpReqFailed", map[string]interface{}{"err": err.Error()}, err) + } + } + if resp.StatusCode == 404 { + return nil, buserr.New("ErrHttpReqNotFound") + } + + return resp, nil +} + +func HandleRequest(url, method string, timeout int) (int, []byte, error) { + defer func() { + if r := recover(); r != nil { + global.LOG.Errorf("handle request failed, error message: %v", r) + return + } + }() + + transport := loadRequestTransport() + client := http.Client{Timeout: time.Duration(timeout) * time.Second, Transport: transport} + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) + defer cancel() + request, err := http.NewRequestWithContext(ctx, method, url, nil) + if err != nil { + return 0, nil, err + } + request.Header.Set("Content-Type", "application/json") + resp, err := client.Do(request) + if err != nil { + return 0, nil, err + } + if resp.StatusCode != http.StatusOK { + return 0, nil, errors.New(resp.Status) + } + body, err := io.ReadAll(resp.Body) + if err != nil { + return 0, nil, err + } + defer resp.Body.Close() + + return resp.StatusCode, body, nil +} + +func loadRequestTransport() *http.Transport { + return &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + DialContext: (&net.Dialer{ + Timeout: 60 * time.Second, + KeepAlive: 60 * time.Second, + }).DialContext, + TLSHandshakeTimeout: 5 * time.Second, + ResponseHeaderTimeout: 10 * time.Second, + IdleConnTimeout: 15 * time.Second, + } +} diff --git a/agent/utils/xpack/xpack.go b/agent/utils/xpack/xpack.go index 2dfeedae1..81736fb37 100644 --- a/agent/utils/xpack/xpack.go +++ b/agent/utils/xpack/xpack.go @@ -3,12 +3,8 @@ package xpack import ( - "crypto/tls" "fmt" - "net" - "net/http" "strings" - "time" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/model" @@ -19,19 +15,6 @@ import ( func RemoveTamper(website string) {} -func LoadRequestTransport() *http.Transport { - return &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - DialContext: (&net.Dialer{ - Timeout: 60 * time.Second, - KeepAlive: 60 * time.Second, - }).DialContext, - TLSHandshakeTimeout: 5 * time.Second, - ResponseHeaderTimeout: 10 * time.Second, - IdleConnTimeout: 15 * time.Second, - } -} - func LoadGpuInfo() []interface{} { return nil } diff --git a/core/app/service/backup.go b/core/app/service/backup.go index 6083991ff..bc75023f8 100644 --- a/core/app/service/backup.go +++ b/core/app/service/backup.go @@ -21,7 +21,7 @@ import ( "github.com/1Panel-dev/1Panel/core/utils/cloud_storage" "github.com/1Panel-dev/1Panel/core/utils/cloud_storage/client" "github.com/1Panel-dev/1Panel/core/utils/encrypt" - httpUtils "github.com/1Panel-dev/1Panel/core/utils/http" + "github.com/1Panel-dev/1Panel/core/utils/req_helper" "github.com/1Panel-dev/1Panel/core/utils/xpack" "github.com/jinzhu/copier" "github.com/pkg/errors" @@ -168,7 +168,7 @@ func (u *BackupService) Delete(id uint) error { if backup.Type == constant.Local { return buserr.New(constant.ErrBackupLocal) } - if _, err := httpUtils.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%v", id), http.MethodGet, nil); err != nil { + if _, err := req_helper.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%v", id), http.MethodGet, nil); err != nil { global.LOG.Errorf("check used of local cronjob failed, err: %v", err) return buserr.New(constant.ErrBackupInUsed) } @@ -370,5 +370,5 @@ func syncAccountToAgent(backup model.BackupAccount, operation string) { itemJson := dto.SyncToAgent{Name: backup.Name, Operation: operation, Data: string(itemData)} bodyItem, _ := json.Marshal(itemJson) _ = xpack.RequestToAllAgent("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem))) - _, _ = httpUtils.NewLocalClient("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem))) + _, _ = req_helper.NewLocalClient("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem))) } diff --git a/core/app/service/group.go b/core/app/service/group.go index 0ab212e8c..ce040d4f6 100644 --- a/core/app/service/group.go +++ b/core/app/service/group.go @@ -11,7 +11,7 @@ import ( "github.com/1Panel-dev/1Panel/core/buserr" "github.com/1Panel-dev/1Panel/core/constant" "github.com/1Panel-dev/1Panel/core/global" - httpUtils "github.com/1Panel-dev/1Panel/core/utils/http" + "github.com/1Panel-dev/1Panel/core/utils/req_helper" "github.com/1Panel-dev/1Panel/core/utils/xpack" "github.com/jinzhu/copier" "github.com/pkg/errors" @@ -92,7 +92,7 @@ func (u *GroupService) Delete(id uint) error { err = xpack.UpdateGroup("node", id, defaultGroup.ID) case "website": bodyItem := []byte(fmt.Sprintf(`{"Group":%v, "NewGroup":%v}`, id, defaultGroup.ID)) - if _, err := httpUtils.NewLocalClient("/api/v2/websites/group/change", http.MethodPost, bytes.NewReader(bodyItem)); err != nil { + if _, err := req_helper.NewLocalClient("/api/v2/websites/group/change", http.MethodPost, bytes.NewReader(bodyItem)); err != nil { return err } if err := xpack.UpdateGroup("node", id, defaultGroup.ID); err != nil { diff --git a/core/app/service/upgrade.go b/core/app/service/upgrade.go index 6e461de03..c95bb41f9 100644 --- a/core/app/service/upgrade.go +++ b/core/app/service/upgrade.go @@ -18,7 +18,7 @@ import ( "github.com/1Panel-dev/1Panel/core/utils/cmd" "github.com/1Panel-dev/1Panel/core/utils/common" "github.com/1Panel-dev/1Panel/core/utils/files" - httpUtil "github.com/1Panel-dev/1Panel/core/utils/http" + "github.com/1Panel-dev/1Panel/core/utils/req_helper" ) type UpgradeService struct{} @@ -264,7 +264,7 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion, mode string) if !isLatest { path = fmt.Sprintf("%s/%s/latest.current", global.CONF.System.RepoUrl, mode) } - _, latestVersionRes, err := httpUtil.HandleGet(path, http.MethodGet, constant.TimeOut20s) + _, latestVersionRes, err := req_helper.HandleRequestWithProxy(path, http.MethodGet, constant.TimeOut20s) if err != nil { global.LOG.Errorf("load latest version from oss failed, err: %v", err) return "" @@ -325,7 +325,7 @@ func (u *UpgradeService) checkVersion(v2, v1 string) string { } func (u *UpgradeService) loadReleaseNotes(path string) (string, error) { - _, releaseNotes, err := httpUtil.HandleGet(path, http.MethodGet, constant.TimeOut20s) + _, releaseNotes, err := req_helper.HandleRequestWithProxy(path, http.MethodGet, constant.TimeOut20s) if err != nil { return "", err } diff --git a/core/cmd/server/conf/app.yaml b/core/cmd/server/conf/app.yaml index cd5dbc0c4..bcf952070 100644 --- a/core/cmd/server/conf/app.yaml +++ b/core/cmd/server/conf/app.yaml @@ -5,7 +5,7 @@ system: repo_url: https://resource.fit2cloud.com/1panel/package app_repo: https://apps-assets.fit2cloud.com is_demo: false - is_intl: true + is_intl: false port: 9999 username: admin password: admin123 diff --git a/core/utils/files/files.go b/core/utils/files/files.go index 3456c0d3b..c0f236d75 100644 --- a/core/utils/files/files.go +++ b/core/utils/files/files.go @@ -16,7 +16,7 @@ import ( "github.com/1Panel-dev/1Panel/core/constant" "github.com/1Panel-dev/1Panel/core/global" "github.com/1Panel-dev/1Panel/core/utils/cmd" - httpUtil "github.com/1Panel-dev/1Panel/core/utils/http" + "github.com/1Panel-dev/1Panel/core/utils/req_helper" ) func CopyFile(src, dst string, withName bool) error { @@ -146,7 +146,7 @@ func HandleUnTar(sourceFile, targetDir string, secret string) error { } func DownloadFile(url, dst string) error { - resp, err := httpUtil.GetHttpRes(url) + resp, err := req_helper.HandleGet(url) if err != nil { return err } @@ -165,7 +165,7 @@ func DownloadFile(url, dst string) error { } func DownloadFileWithProxy(url, dst string) error { - _, resp, err := httpUtil.HandleGet(url, http.MethodGet, constant.TimeOut5m) + _, resp, err := req_helper.HandleRequestWithProxy(url, http.MethodGet, constant.TimeOut5m) if err != nil { return err } diff --git a/core/utils/http/http.go b/core/utils/req_helper/http.go similarity index 73% rename from core/utils/http/http.go rename to core/utils/req_helper/http.go index 5ceded012..7757ba7e2 100644 --- a/core/utils/http/http.go +++ b/core/utils/req_helper/http.go @@ -1,4 +1,4 @@ -package http +package req_helper import ( "context" @@ -12,9 +12,10 @@ import ( "github.com/1Panel-dev/1Panel/core/buserr" "github.com/1Panel-dev/1Panel/core/global" + "github.com/1Panel-dev/1Panel/core/utils/xpack" ) -func HandleGet(url, method string, timeout int) (int, []byte, error) { +func HandleRequest(url, method string, timeout int) (int, []byte, error) { transport := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, DialContext: (&net.Dialer{ @@ -25,10 +26,15 @@ func HandleGet(url, method string, timeout int) (int, []byte, error) { ResponseHeaderTimeout: 10 * time.Second, IdleConnTimeout: 15 * time.Second, } - return HandleGetWithTransport(url, method, transport, timeout) + return handleRequestWithTransport(url, method, transport, timeout) } -func HandleGetWithTransport(url, method string, transport *http.Transport, timeout int) (int, []byte, error) { +func HandleRequestWithProxy(url, method string, timeout int) (int, []byte, error) { + transport := xpack.LoadRequestTransport() + return handleRequestWithTransport(url, method, transport, timeout) +} + +func handleRequestWithTransport(url, method string, transport *http.Transport, timeout int) (int, []byte, error) { defer func() { if r := recover(); r != nil { global.LOG.Errorf("handle request failed, error message: %v", r) @@ -57,10 +63,7 @@ func HandleGetWithTransport(url, method string, transport *http.Transport, timeo return resp.StatusCode, body, nil } -func GetHttpRes(url string) (*http.Response, error) { - client := &http.Client{ - Timeout: time.Second * 300, - } +func HandleGet(url string) (*http.Response, error) { transport := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, DialContext: (&net.Dialer{ @@ -71,6 +74,18 @@ func GetHttpRes(url string) (*http.Response, error) { ResponseHeaderTimeout: 10 * time.Second, IdleConnTimeout: 15 * time.Second, } + return handleGetWithTransport(url, transport) +} + +func HandleGetWithProxy(url string) (*http.Response, error) { + transport := xpack.LoadRequestTransport() + return handleGetWithTransport(url, transport) +} + +func handleGetWithTransport(url string, transport *http.Transport) (*http.Response, error) { + client := &http.Client{ + Timeout: time.Second * 300, + } client.Transport = transport req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil) diff --git a/core/utils/http/new.go b/core/utils/req_helper/req_to_local.go similarity index 98% rename from core/utils/http/new.go rename to core/utils/req_helper/req_to_local.go index 163a7c14c..c6c37c3c0 100644 --- a/core/utils/http/new.go +++ b/core/utils/req_helper/req_to_local.go @@ -1,4 +1,4 @@ -package http +package req_helper import ( "context" diff --git a/core/utils/xpack/xpack.go b/core/utils/xpack/xpack.go index 1127a7d51..d5ed4ae80 100644 --- a/core/utils/xpack/xpack.go +++ b/core/utils/xpack/xpack.go @@ -3,7 +3,11 @@ package xpack import ( + "crypto/tls" "io" + "net" + "net/http" + "time" "github.com/gin-gonic/gin" ) @@ -15,3 +19,16 @@ func UpdateGroup(name string, group, newGroup uint) error { return nil } func CheckBackupUsed(id uint) error { return nil } func RequestToAllAgent(reqUrl, reqMethod string, reqBody io.Reader) error { return nil } + +func LoadRequestTransport() *http.Transport { + return &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + DialContext: (&net.Dialer{ + Timeout: 60 * time.Second, + KeepAlive: 60 * time.Second, + }).DialContext, + TLSHandshakeTimeout: 5 * time.Second, + ResponseHeaderTimeout: 10 * time.Second, + IdleConnTimeout: 15 * time.Second, + } +} diff --git a/frontend/package.json b/frontend/package.json index c2924c8d0..a9f099173 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,6 +21,8 @@ }, "dependencies": { "@codemirror/lang-json": "^6.0.1", + "@codemirror/lang-html": "^6.4.9", + "@codemirror/lang-php": "^6.0.1", "@codemirror/language": "^6.10.2", "@codemirror/legacy-modes": "^6.4.0", "@codemirror/theme-one-dark": "^6.1.2", diff --git a/frontend/src/layout/components/Sidebar/index.vue b/frontend/src/layout/components/Sidebar/index.vue index 117585fae..ff2422652 100644 --- a/frontend/src/layout/components/Sidebar/index.vue +++ b/frontend/src/layout/components/Sidebar/index.vue @@ -10,7 +10,7 @@ -