Skip to content

Commit

Permalink
Merge pull request #496 from qiniu/update_response
Browse files Browse the repository at this point in the history
add request method.
  • Loading branch information
bachue authored Sep 10, 2020
2 parents 9bc7deb + 8c30946 commit 3be435d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/java/com/qiniu/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.qiniu.util.StringMap;
import com.qiniu.util.StringUtils;
import okhttp3.MediaType;
import okhttp3.Request;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -19,6 +20,10 @@ public final class Response {
public static final int InvalidFile = -3;
public static final int Cancelled = -2;
public static final int NetworkError = -1;
/**
* 请求方法
*/
public final String method;
/**
* 回复状态码
*/
Expand Down Expand Up @@ -62,6 +67,21 @@ private Response(okhttp3.Response response, int statusCode, String reqId, String
this.error = error;
this.address = address;
this.body = body;
this.method = getMethod(response);
}

private String getMethod(okhttp3.Response response) {
String method = null;
if (response != null) {
Request req = response.request();
if (req != null) {
method = req.method();
}
}
if (method == null) {
method = "";
}
return method;
}

public static Response create(okhttp3.Response response, String address, double duration) {
Expand Down Expand Up @@ -227,7 +247,8 @@ public String url() {
public String getInfo() {
String[] msg = new String[3];
try {
msg[0] = url();
msg[0] = this.method;
msg[0] += (" " + url());
} catch (Throwable t) {
}
try {
Expand Down

0 comments on commit 3be435d

Please sign in to comment.