|
8 | 8 |
|
9 | 9 | var fetchFailedCount = 0 |
10 | 10 |
|
11 | | -func NewRequest(isPOST bool, url string, postdata string, external bool, withHeader *map[string]string) *http.Request { |
| 11 | +func NewRequest(isPOST bool, url string, postdata string, clientReq bool, withHeader *map[string]string) *http.Request { |
12 | 12 | var request *http.Request |
13 | 13 | var err error |
14 | 14 |
|
@@ -47,26 +47,28 @@ func NewRequest(isPOST bool, url string, postdata string, external bool, withHea |
47 | 47 | request.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
48 | 48 | } |
49 | 49 |
|
50 | | - if currentClientType == "Transmission" && external && Tr_csrfToken != "" { |
51 | | - request.Header.Set("X-Transmission-Session-Id", Tr_csrfToken) |
52 | | - } |
| 50 | + if clientReq { |
| 51 | + if currentClientType == "Transmission" && Tr_csrfToken != "" { |
| 52 | + request.Header.Set("X-Transmission-Session-Id", Tr_csrfToken) |
| 53 | + } |
53 | 54 |
|
54 | | - if external && config.UseBasicAuth && config.ClientUsername != "" { |
55 | | - request.SetBasicAuth(config.ClientUsername, config.ClientPassword) |
| 55 | + if config.UseBasicAuth && config.ClientUsername != "" { |
| 56 | + request.SetBasicAuth(config.ClientUsername, config.ClientPassword) |
| 57 | + } |
56 | 58 | } |
57 | 59 |
|
58 | 60 | return request |
59 | 61 | } |
60 | | -func Fetch(url string, tryLogin bool, external bool, withHeader *map[string]string) (int, http.Header, []byte) { |
61 | | - request := NewRequest(false, url, "", external, withHeader) |
| 62 | +func Fetch(url string, tryLogin bool, clientReq bool, withHeader *map[string]string) (int, http.Header, []byte) { |
| 63 | + request := NewRequest(false, url, "", clientReq, withHeader) |
62 | 64 | if request == nil { |
63 | 65 | return -1, nil, nil |
64 | 66 | } |
65 | 67 |
|
66 | 68 | var response *http.Response |
67 | 69 | var err error |
68 | 70 |
|
69 | | - if external { |
| 71 | + if clientReq { |
70 | 72 | response, err = httpClient.Do(request) |
71 | 73 | } else { |
72 | 74 | response, err = httpClientExternal.Do(request) |
@@ -141,16 +143,16 @@ func Fetch(url string, tryLogin bool, external bool, withHeader *map[string]stri |
141 | 143 |
|
142 | 144 | return response.StatusCode, response.Header, responseBody |
143 | 145 | } |
144 | | -func Submit(url string, postdata string, tryLogin bool, external bool, withHeader *map[string]string) (int, http.Header, []byte) { |
145 | | - request := NewRequest(true, url, postdata, external, withHeader) |
| 146 | +func Submit(url string, postdata string, tryLogin bool, clientReq bool, withHeader *map[string]string) (int, http.Header, []byte) { |
| 147 | + request := NewRequest(true, url, postdata, clientReq, withHeader) |
146 | 148 | if request == nil { |
147 | 149 | return -1, nil, nil |
148 | 150 | } |
149 | 151 |
|
150 | 152 | var response *http.Response |
151 | 153 | var err error |
152 | 154 |
|
153 | | - if external { |
| 155 | + if clientReq { |
154 | 156 | response, err = httpClient.Do(request) |
155 | 157 | } else { |
156 | 158 | response, err = httpClientExternal.Do(request) |
|
0 commit comments