Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ private static ResponseInfo buildResponseInfo(int statusCode, Header[] headers,
String reqId = null;
String xlog = null;
String ip = null;
String xvia = null;
if (headers != null) {
for (Header h : headers) {
if ("X-Reqid".equals(h.getName())) {
reqId = h.getValue();
} else if ("X-Log".equals(h.getName())) {
xlog = h.getValue();
} else if ("X-Via".equals(h.getName())){
xvia = h.getValue();
} else if ("X-Px".equals(h.getName())){
xvia = h.getValue();
}
}
}
Expand Down Expand Up @@ -102,7 +107,7 @@ private static ResponseInfo buildResponseInfo(int statusCode, Header[] headers,
statusCode = ResponseInfo.NetworkError;
}

return new ResponseInfo(statusCode, reqId, xlog, host, ip, duration, err);
return new ResponseInfo(statusCode, reqId, xlog, xvia, host, ip, duration, err);
}

private static JSONObject buildJsonResp(byte[] body) throws Exception {
Expand All @@ -121,15 +126,15 @@ public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
exception = e;
}
ResponseInfo info = buildResponseInfo(statusCode, headers, null, host, duration, exception);
Log.i("qiniu----success", info.toString());
Log.i("upload----success", info.toString());
completionHandler.complete(info, obj);
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
double duration = (System.currentTimeMillis() - reqStartTime) / 1000.0;
ResponseInfo info = buildResponseInfo(statusCode, headers, responseBody, host, duration, error);
Log.i("qiniu----failed", info.toString());
Log.i("upload----failed", info.toString());
completionHandler.complete(info, null);
}

Expand Down
17 changes: 11 additions & 6 deletions library/src/main/java/com/qiniu/android/http/ResponseInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public final class ResponseInfo {
* 七牛日志扩展头
*/
public final String xlog;
/**
* cdn日志扩展头
*/
public final String xvia;
/**
* 错误信息
*/
Expand All @@ -40,28 +44,29 @@ public final class ResponseInfo {
*/
public final String ip;

public ResponseInfo(int statusCode, String reqId, String xlog, String host, String ip, double duration, String error) {
public ResponseInfo(int statusCode, String reqId, String xlog, String xvia, String host, String ip, double duration, String error) {
this.statusCode = statusCode;
this.reqId = reqId;
this.xlog = xlog;
this.xvia = xvia;
this.host = host;
this.duration = duration;
this.error = error;
this.ip = ip;
}

public static ResponseInfo cancelled() {
return new ResponseInfo(Cancelled, "", "", "", "", 0, "cancelled by user");
return new ResponseInfo(Cancelled, "", "", "", "", "", 0, "cancelled by user");
}

public static ResponseInfo invalidArgument(String message) {
return new ResponseInfo(InvalidArgument, "", "", "", "", 0,
return new ResponseInfo(InvalidArgument, "","", "", "", "", 0,
message);
}


public static ResponseInfo fileError(Exception e) {
return new ResponseInfo(InvalidFile, "", "", "", "",
return new ResponseInfo(InvalidFile, "","", "", "", "",
0, e.getMessage());
}

Expand Down Expand Up @@ -90,7 +95,7 @@ public boolean needRetry() {
}

public String toString() {
return String.format(Locale.ENGLISH, "{ResponseInfo:%s,status:%d, reqId:%s, xlog:%s, host:%s, ip:%s, duration:%f s, error:%s}",
super.toString(), statusCode, reqId, xlog, host, ip, duration, error);
return String.format(Locale.ENGLISH, "{ResponseInfo:%s,status:%d, reqId:%s, xlog:%s, xvia:%s, host:%s, ip:%s, duration:%f s, error:%s}",
super.toString(), statusCode, reqId, xlog, xvia, host, ip, duration, error);
}
}