Skip to content

Commit 3be435d

Browse files
authored
Merge pull request #496 from qiniu/update_response
add request method.
2 parents 9bc7deb + 8c30946 commit 3be435d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/main/java/com/qiniu/http/Response.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.qiniu.util.StringMap;
77
import com.qiniu.util.StringUtils;
88
import okhttp3.MediaType;
9+
import okhttp3.Request;
910

1011
import java.io.IOException;
1112
import java.io.InputStream;
@@ -19,6 +20,10 @@ public final class Response {
1920
public static final int InvalidFile = -3;
2021
public static final int Cancelled = -2;
2122
public static final int NetworkError = -1;
23+
/**
24+
* 请求方法
25+
*/
26+
public final String method;
2227
/**
2328
* 回复状态码
2429
*/
@@ -62,6 +67,21 @@ private Response(okhttp3.Response response, int statusCode, String reqId, String
6267
this.error = error;
6368
this.address = address;
6469
this.body = body;
70+
this.method = getMethod(response);
71+
}
72+
73+
private String getMethod(okhttp3.Response response) {
74+
String method = null;
75+
if (response != null) {
76+
Request req = response.request();
77+
if (req != null) {
78+
method = req.method();
79+
}
80+
}
81+
if (method == null) {
82+
method = "";
83+
}
84+
return method;
6585
}
6686

6787
public static Response create(okhttp3.Response response, String address, double duration) {
@@ -227,7 +247,8 @@ public String url() {
227247
public String getInfo() {
228248
String[] msg = new String[3];
229249
try {
230-
msg[0] = url();
250+
msg[0] = this.method;
251+
msg[0] += (" " + url());
231252
} catch (Throwable t) {
232253
}
233254
try {

0 commit comments

Comments
 (0)