diff --git a/README.en.md b/README.en.md index a38506d..9a5c9c8 100644 --- a/README.en.md +++ b/README.en.md @@ -147,7 +147,7 @@ Docker version is configured through the same name variable configuration, which | ignoreFailureExit | bool | false | Ignore failure exit. If enabled, it will continue to retry after first detection of the client fails or authentication fails | | sleepTime | uint32 | 20 (MicroSec) | Query waiting time of each Torrent Peers. Short interval can make blocking Peer faster but may cause client lag, Long interval can help average CPU usage | | timeout | uint32 | 6 (MillSec) | Request timeout. If interval is too short, peer may not be properly blocked. If interval is too long, timeout request will affect blocking other peer | -| proxy | string | Auto | Use proxy. Proxy will still automatically detect proxy on first load. Empty: Disable proxy; Auto: Automatic (use proxy only for external resources); All: Use proxy | +| proxy | string | Auto | Use proxy. Still automatically detect proxy on first load. Empty: Disable proxy; Auto: Automatic (use proxy only for external requests); All: Use proxy for all requests | | longConnection | bool | true | Long connection. Enable to reduce resource consumption | | logPath | string | logs | Log path. Must enable logToFile | | logToFile | bool | true | Log general information to file. If enabled, it can be used for general analysis and statistical purposes | diff --git a/README.md b/README.md index 7b159ea..9918562 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Docker 版本通过相同名称的环境变量配置, 通过自动转换环境 | ignoreFailureExit | bool | false (禁用) | 忽略失败退出. 启用后会使得首次检测客户端失败或认证失败后继续重试 | | sleepTime | uint32 | 20 (毫秒) | 查询每个 Torrent Peers 的等待时间. 短间隔可使屏蔽 Peer 更快但可能造成客户端卡顿, 长间隔有助于平均 CPU 资源占用 | | timeout | uint32 | 6 (秒) | 请求超时. 过短间隔可能会造成无法正确屏蔽 Peer, 过长间隔会使超时请求影响屏蔽其它 Peer 的性能 | -| proxy | string | Auto (自动) | 使用代理. 仍会在首次加载配置文件时自动检测代理. 空: 禁止使用代理; Auto: 自动 (仅对外部资源使用代理); All: 使用代理 | +| proxy | string | Auto (自动) | 使用代理. 仍会在首次加载配置文件时自动检测代理. 空: 禁止使用代理; Auto: 自动 (仅对外部请求使用代理); All: 对全部请求使用代理 | | longConnection | bool | true (启用) | 长连接. 启用可降低资源消耗 | | logPath | string | logs | 日志目录. 须先启用 logToFile | | logToFile | bool | true (启用) | 记录普通信息到日志. 启用后可用于一般的分析及统计用途 | diff --git a/request.go b/request.go index 752c144..56fce83 100644 --- a/request.go +++ b/request.go @@ -8,7 +8,7 @@ import ( var fetchFailedCount = 0 -func NewRequest(isPOST bool, url string, postdata string, external bool, withHeader *map[string]string) *http.Request { +func NewRequest(isPOST bool, url string, postdata string, clientReq bool, withHeader *map[string]string) *http.Request { var request *http.Request var err error @@ -47,18 +47,20 @@ func NewRequest(isPOST bool, url string, postdata string, external bool, withHea request.Header.Set("Content-Type", "application/x-www-form-urlencoded") } - if currentClientType == "Transmission" && external && Tr_csrfToken != "" { - request.Header.Set("X-Transmission-Session-Id", Tr_csrfToken) - } + if clientReq { + if currentClientType == "Transmission" && Tr_csrfToken != "" { + request.Header.Set("X-Transmission-Session-Id", Tr_csrfToken) + } - if external && config.UseBasicAuth && config.ClientUsername != "" { - request.SetBasicAuth(config.ClientUsername, config.ClientPassword) + if config.UseBasicAuth && config.ClientUsername != "" { + request.SetBasicAuth(config.ClientUsername, config.ClientPassword) + } } return request } -func Fetch(url string, tryLogin bool, external bool, withHeader *map[string]string) (int, http.Header, []byte) { - request := NewRequest(false, url, "", external, withHeader) +func Fetch(url string, tryLogin bool, clientReq bool, withHeader *map[string]string) (int, http.Header, []byte) { + request := NewRequest(false, url, "", clientReq, withHeader) if request == nil { return -1, nil, nil } @@ -66,7 +68,7 @@ func Fetch(url string, tryLogin bool, external bool, withHeader *map[string]stri var response *http.Response var err error - if external { + if clientReq { response, err = httpClient.Do(request) } else { response, err = httpClientExternal.Do(request) @@ -141,8 +143,8 @@ func Fetch(url string, tryLogin bool, external bool, withHeader *map[string]stri return response.StatusCode, response.Header, responseBody } -func Submit(url string, postdata string, tryLogin bool, external bool, withHeader *map[string]string) (int, http.Header, []byte) { - request := NewRequest(true, url, postdata, external, withHeader) +func Submit(url string, postdata string, tryLogin bool, clientReq bool, withHeader *map[string]string) (int, http.Header, []byte) { + request := NewRequest(true, url, postdata, clientReq, withHeader) if request == nil { return -1, nil, nil } @@ -150,7 +152,7 @@ func Submit(url string, postdata string, tryLogin bool, external bool, withHeade var response *http.Response var err error - if external { + if clientReq { response, err = httpClient.Do(request) } else { response, err = httpClientExternal.Do(request)