mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
feat: 下载eapi文件限制郁闷
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -512,8 +513,17 @@ func GetCurrentDay() string {
|
|||||||
return formattedDate
|
return formattedDate
|
||||||
}
|
}
|
||||||
|
|
||||||
func DownloadFile(filePath string, url string) error {
|
func DownloadFile(filePath string, fileUrl string) error {
|
||||||
log.Info().Str("filePath", filePath).Str("url", url).Msg("download file")
|
log.Info().Str("filePath", filePath).Str("url", fileUrl).Msg("download file")
|
||||||
|
parsedURL, err := url.Parse(fileUrl)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if parsedURL.Host != "gtf-eapi-cn.bytedance.com" {
|
||||||
|
return errors.New("invalid domain: must be gtf-eapi-cn.bytedance.com")
|
||||||
|
}
|
||||||
|
|
||||||
out, err := os.Create(filePath)
|
out, err := os.Create(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -521,7 +531,7 @@ func DownloadFile(filePath string, url string) error {
|
|||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
// 创建一个新的 HTTP 请求
|
// 创建一个新的 HTTP 请求
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", fileUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user