-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from longbai/proxy
add proxy
- Loading branch information
Showing
10 changed files
with
116 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
#Changelog | ||
|
||
## 7.2.1 (2016-07-14) | ||
|
||
### 修正 | ||
* 当出现异常服务端返回为空时会造成NPE | ||
|
||
### 增加 | ||
* proxy 支持 | ||
|
||
## 7.2.0 (2016-04-29) | ||
|
||
### 修改 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
library/src/main/java/com/qiniu/android/http/ProxyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.qiniu.android.http; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.Proxy; | ||
|
||
import okhttp3.Authenticator; | ||
import okhttp3.Credentials; | ||
import okhttp3.Route; | ||
|
||
/** | ||
* http 代理 | ||
*/ | ||
public final class ProxyConfiguration { | ||
|
||
public final String hostAddress; | ||
public final int port; | ||
public final String user; | ||
public final String password; | ||
public final Proxy.Type type; | ||
|
||
/** | ||
* @param hostAddress 服务器域名或IP,比如proxy.com, 192.168.1.1 | ||
* @param port 端口 | ||
* @param user 用户名,无则填null | ||
* @param password 用户密码,无则填null | ||
*/ | ||
public ProxyConfiguration(String hostAddress, int port, String user, String password, java.net.Proxy.Type type) { | ||
this.hostAddress = hostAddress; | ||
this.port = port; | ||
this.user = user; | ||
this.password = password; | ||
this.type = type; | ||
} | ||
|
||
public ProxyConfiguration(String hostAddress, int port) { | ||
this(hostAddress, port, null, null, Proxy.Type.HTTP); | ||
} | ||
Proxy proxy(){ | ||
return new Proxy(type, new InetSocketAddress(hostAddress, port)); | ||
} | ||
|
||
Authenticator authenticator(){ | ||
return new Authenticator() { | ||
@Override | ||
public okhttp3.Request authenticate(Route route, okhttp3.Response response) throws IOException { | ||
String credential = Credentials.basic(user, password); | ||
return response.request().newBuilder(). | ||
header("Proxy-Authorization", credential). | ||
header("Proxy-Connection", "Keep-Alive").build(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters