Skip to content

Commit 0866665

Browse files
committed
增加代理支持
1 parent f21f9bc commit 0866665

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

library/src/main/java/com/qiniu/android/http/HttpManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ public final class HttpManager {
2121
private AsyncHttpClient client;
2222

2323

24-
public HttpManager() {
24+
public HttpManager(Proxy proxy) {
2525
client = new AsyncHttpClient();
2626
client.setConnectTimeout(Config.CONNECT_TIMEOUT);
2727
client.setResponseTimeout(Config.RESPONSE_TIMEOUT);
2828
client.setUserAgent(userAgent);
2929
client.setEnableRedirects(false);
30+
if (proxy != null){
31+
client.setProxy(proxy.hostAddress, proxy.port, proxy.user, proxy.password);
32+
}
3033
}
3134

3235
private static String genId() {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.qiniu.android.http;
2+
3+
/**
4+
* http 代理
5+
*/
6+
public class Proxy {
7+
8+
public final String hostAddress;
9+
public final int port;
10+
public final String user;
11+
public final String password;
12+
13+
/**
14+
*
15+
* @param hostAddress 服务器域名或IP,比如proxy.com, 192.168.1.1
16+
* @param port 端口
17+
* @param user 用户名,无则填null
18+
* @param password 用户密码,无则填null
19+
*/
20+
public Proxy(String hostAddress, int port, String user, String password) {
21+
this.hostAddress = hostAddress;
22+
this.port = port;
23+
this.user = user;
24+
this.password = password;
25+
}
26+
}

library/src/main/java/com/qiniu/android/storage/KeyGenerator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
import java.io.File;
44

55
/**
6-
* Created by bailong on 14/10/21.
6+
* 本地持久化上传纪录key生成工具
77
*/
88
public interface KeyGenerator {
9+
/**
10+
* 根据服务器的key和本地文件名生成持久化纪录的key
11+
* @param key 服务器的key
12+
* @param file 本地文件名
13+
* @return 持久化上传纪录的key
14+
*/
915
String gen(String key, File file);
1016
}

library/src/main/java/com/qiniu/android/storage/UploadManager.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.qiniu.android.common.Config;
44
import com.qiniu.android.http.HttpManager;
5+
import com.qiniu.android.http.Proxy;
56
import com.qiniu.android.http.ResponseInfo;
67
import com.qiniu.android.utils.AsyncRun;
78

@@ -19,17 +20,27 @@ public final class UploadManager {
1920
private final KeyGenerator keyGen;
2021

2122
public UploadManager() {
22-
this(null, null);
23+
this(null, null, null);
2324
}
2425

2526
public UploadManager(Recorder recorder, KeyGenerator keyGen) {
27+
this(recorder, keyGen, null);
28+
}
29+
30+
/**
31+
*
32+
* @param recorder 本地持久化断点上传纪录的类
33+
* @param keyGen 本地持久化断点上传纪录时需要的key生成器
34+
* @param proxy http 代理
35+
*/
36+
public UploadManager(Recorder recorder, KeyGenerator keyGen, Proxy proxy) {
2637
this.recorder = recorder;
27-
this.httpManager = new HttpManager();
38+
this.httpManager = new HttpManager(proxy);
2839
this.keyGen = keyGen;
2940
}
3041

3142
public UploadManager(Recorder recorder) {
32-
this(recorder, null);
43+
this(recorder, null, null);
3344
}
3445

3546
private static boolean areInvalidArg(final String key, byte[] data, File f, String token, final UpCompletionHandler completionHandler) {

0 commit comments

Comments
 (0)