88import okhttp3 .MediaType ;
99
1010import java .io .IOException ;
11+ import java .io .InputStream ;
1112import java .util .Locale ;
1213
1314/**
@@ -67,11 +68,11 @@ public static Response create(okhttp3.Response response, String address, double
6768 String error = null ;
6869 int code = response .code ();
6970 String reqId = null ;
71+ reqId = response .header ("X-Reqid" );
72+ reqId = (reqId == null ) ? null : reqId .trim ();
7073
7174 byte [] body = null ;
7275 if (ctype (response ).equals (Client .JsonMime )) {
73- reqId = response .header ("X-Reqid" );
74- reqId = (reqId == null ) ? null : reqId .trim ();
7576 try {
7677 body = response .body ().bytes ();
7778 if (response .code () >= 400 && !StringUtils .isNullOrEmpty (reqId ) && body != null ) {
@@ -94,11 +95,11 @@ static Response createError(okhttp3.Response response, String address, double du
9495 }
9596 int code = response .code ();
9697 String reqId = null ;
98+ reqId = response .header ("X-Reqid" );
99+ reqId = (reqId == null ) ? null : reqId .trim ();
97100
98101 byte [] body = null ;
99102 if (ctype (response ).equals (Client .JsonMime )) {
100- reqId = response .header ("X-Reqid" );
101- reqId = (reqId == null ) ? null : reqId .trim ();
102103 try {
103104 body = response .body ().bytes ();
104105 if (response .code () >= 400 && !StringUtils .isNullOrEmpty (reqId ) && body != null ) {
@@ -198,6 +199,13 @@ public String bodyString() throws QiniuException {
198199 return StringUtils .utf8String (body ());
199200 }
200201
202+ public synchronized InputStream bodyStream () throws QiniuException {
203+ if (this .response == null ) {
204+ return null ;
205+ }
206+ return this .response .body ().byteStream ();
207+ }
208+
201209 public String contentType () {
202210 return ctype (response );
203211 }
0 commit comments