From f4ccce3f9685149fca2a22a1a8c32c20b7e0f6bc Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Mon, 28 Oct 2024 17:13:50 +0100 Subject: [PATCH] KTOR-7623 Evaluate trace logs lazily in WebSockets client plugin --- .../io/ktor/client/plugins/websocket/WebSockets.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/websocket/WebSockets.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/websocket/WebSockets.kt index fa30d2ffaf0..30cd810efa1 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/websocket/WebSockets.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/websocket/WebSockets.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.client.plugins.websocket @@ -150,11 +150,11 @@ public class WebSockets internal constructor( scope.requestPipeline.intercept(HttpRequestPipeline.Render) { if (!context.url.protocol.isWebsocket()) { - LOGGER.trace("Skipping WebSocket plugin for non-websocket request: ${context.url}") + LOGGER.trace { "Skipping WebSocket plugin for non-websocket request: ${context.url}" } return@intercept } - LOGGER.trace("Sending WebSocket request ${context.url}") + LOGGER.trace { "Sending WebSocket request ${context.url}" } context.setCapability(WebSocketCapability, Unit) if (extensionsSupported) { @@ -170,7 +170,7 @@ public class WebSockets internal constructor( val requestContent = response.request.content if (requestContent !is WebSocketContent) { - LOGGER.trace("Skipping non-websocket response from ${context.request.url}: $session") + LOGGER.trace { "Skipping non-websocket response from ${context.request.url}: $requestContent" } return@intercept } if (status != HttpStatusCode.SwitchingProtocols) { @@ -180,11 +180,11 @@ public class WebSockets internal constructor( } if (session !is WebSocketSession) { throw WebSocketException( - "Handshake exception, expected `WebSocketSession` content but was $session" + "Handshake exception, expected `WebSocketSession` content but was ${session::class}" ) } - LOGGER.trace("Receive websocket session from ${context.request.url}: $session") + LOGGER.trace { "Receive websocket session from ${context.request.url}: $session" } if (plugin.maxFrameSize != Int.MAX_VALUE.toLong()) { session.maxFrameSize = plugin.maxFrameSize