Feature: add custom request header to proxy provider

`header` value is type of string array
header:
  Accept:
    - 'application/vnd.github.v3.raw'
  Authorization:
    - ' token xxxxxxxxxxx'
  User-Agent:
    - 'Clash/v1.10.6'

`prefix-name` add a prefix to proxy name
prefix-name: 'XXX-'
This commit is contained in:
yaling888
2022-06-03 05:00:13 +08:00
parent 8ed868b0f5
commit af5bd0f65e
5 changed files with 62 additions and 23 deletions

View File

@@ -6,13 +6,14 @@ import (
"net/http"
"os"
"github.com/Dreamacro/clash/common/convert"
"github.com/Dreamacro/clash/component/mmdb"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
)
func downloadMMDB(path string) (err error) {
resp, err := http.Get("https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb")
resp, err := doGet("https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb")
if err != nil {
return
}
@@ -51,7 +52,7 @@ func initMMDB() error {
}
func downloadGeoSite(path string) (err error) {
resp, err := http.Get("https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat")
resp, err := doGet("https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat")
if err != nil {
return
}
@@ -110,3 +111,16 @@ func Init(dir string) error {
}
return nil
}
func doGet(url string) (resp *http.Response, err error) {
var req *http.Request
req, err = http.NewRequest("GET", url, nil)
if err != nil {
return
}
convert.SetUserAgent(req)
resp, err = http.DefaultClient.Do(req)
return
}