Skip to content

Commit 10be0cf

Browse files
committed
Merge pull request #89 from longbai/proxy
增加代理支持
2 parents f21f9bc + 2dc5732 commit 10be0cf

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ public final class HttpManager {
2020
private static final String userAgent = getUserAgent();
2121
private AsyncHttpClient client;
2222

23-
24-
public HttpManager() {
23+
public HttpManager(Proxy proxy) {
2524
client = new AsyncHttpClient();
2625
client.setConnectTimeout(Config.CONNECT_TIMEOUT);
2726
client.setResponseTimeout(Config.RESPONSE_TIMEOUT);
2827
client.setUserAgent(userAgent);
2928
client.setEnableRedirects(false);
29+
if (proxy != null){
30+
client.setProxy(proxy.hostAddress, proxy.port, proxy.user, proxy.password);
31+
}
32+
}
33+
34+
public HttpManager() {
35+
this(null);
3036
}
3137

3238
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)