Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request method. #496

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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