Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
sxci committed Nov 13, 2020
1 parent d0a5ab5 commit 1dc3aa7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/http/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
return response;
}
try {
tag.ip = chain.connection().socket().getRemoteSocketAddress().toString();
tag.ip = chain.connection().socket().getRemoteSocketAddress() + "";
} catch (Exception e) {
// ingore
}
Expand Down
37 changes: 36 additions & 1 deletion src/test/java/test/com/qiniu/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,29 @@ public void testProxy() {

@Test
public void testTimeout() throws NoSuchFieldException, IllegalAccessException {
Client client0 = new Client();
try {
Response res = new Client().get("https://www.qiniu.com/?v=12345");
Response res = client0.get("https://www.qiniu.com/?v=12345");
String r = res.toString();
System.out.println(r);
Assert.assertTrue("https, must have port 443", r.indexOf(":443") > 0);
} catch (QiniuException e) {
e.printStackTrace();
Assert.fail("should be ok");
}

try {
Response res = client0.get("https://www.qiniu.com/?v=12345");
String r = res.toString();
System.out.println(r);
Assert.assertTrue("https, must have port 443", r.indexOf(":443") > 0);
} catch (QiniuException e) {
e.printStackTrace();
Assert.fail("should be ok");
}

try {
Response res = client0.get("https://www.qiniu.com/?v=12345");
String r = res.toString();
System.out.println(r);
Assert.assertTrue("https, must have port 443", r.indexOf(":443") > 0);
Expand All @@ -118,6 +139,20 @@ public void testTimeout() throws NoSuchFieldException, IllegalAccessException {
okHttpClient = okHttpClient.newBuilder().connectTimeout(3, TimeUnit.MILLISECONDS).build();
field.set(client, okHttpClient);

try {
client.get("http://rs.qbox.me/?v=12");
Assert.fail("should be timeout");
} catch (QiniuException e) {
e.printStackTrace();
Assert.assertTrue("http, must have port 80", e.getMessage().indexOf(":80") > 10);
}
try {
client.get("http://rs.qbox.me/?v=12");
Assert.fail("should be timeout");
} catch (QiniuException e) {
e.printStackTrace();
Assert.assertTrue("http, must have port 80", e.getMessage().indexOf(":80") > 10);
}
try {
client.get("http://rs.qbox.me/?v=12");
Assert.fail("should be timeout");
Expand Down

0 comments on commit 1dc3aa7

Please sign in to comment.