@@ -140,12 +140,12 @@ public Response intercept(Chain chain) throws IOException {
140140
141141 Connection connection = chain .connection ();
142142 Protocol protocol = connection != null ? connection .getProtocol () : Protocol .HTTP_1_1 ;
143- String requestStartMessage =
144- "--> " + request .method () + ' ' + request .url () + ' ' + protocol (protocol );
143+ StringBuilder requestStartMessage = new StringBuilder ();
144+ requestStartMessage . append ( "--> " + request .method () + ' ' + request .url () + ' ' + protocol (protocol ) );
145145 if (!logHeaders && hasRequestBody ) {
146- requestStartMessage += " (" + requestBody .contentLength () + BYTE_BODY ;
146+ requestStartMessage . append ( " (" + requestBody .contentLength () + BYTE_BODY ) ;
147147 }
148- logger .log (requestStartMessage );
148+ logger .log (requestStartMessage . toString () );
149149
150150 if (logHeaders ) {
151151 if (hasRequestBody ) {
@@ -241,44 +241,4 @@ private static String protocol(Protocol protocol) {
241241 return protocol == Protocol .HTTP_1_0 ? "HTTP/1.0" : "HTTP/1.1" ;
242242 }
243243
244- /* @Override
245- public Response intercept(Chain chain) throws IOException {
246- Request request = chain.request();
247- long t1 = System.nanoTime();
248- String requestLog = "\t" + request.method() + "::" + request.urlString();
249-
250- if (request.method().compareToIgnoreCase("post") == 0) {
251- requestLog = "\n" + requestLog + "\n" + bodyToString(request);
252- }
253- XgoLog.d("request::\n" + requestLog);
254-
255- Response response = null;
256- String bodyString = null;
257- try {
258- response = chain.proceed(request);
259- bodyString = response.body().string();
260- }catch (Exception e){
261- e.printStackTrace();
262- }
263-
264- long t2 = System.nanoTime();
265-
266- XgoLog.d("response::" + (t2 - t1) / 1e6d + "ms\n" + bodyString);
267-
268-
269- return response==null ? null :response.newBuilder()
270- .body(ResponseBody.create(response.body().contentType(), bodyString))
271- .build();
272- }
273-
274- private static String bodyToString(final Request request) {
275- try {
276- final Request copy = request.newBuilder().build();
277- final Buffer buffer = new Buffer();
278- copy.body().writeTo(buffer);
279- return buffer.readUtf8();
280- } catch (final IOException e) {
281- return "did not work";
282- }
283- }*/
284244}
0 commit comments