Copilot commented on code in PR #6095: URL: https://github.com/apache/shenyu/pull/6095#discussion_r2268677372
########## shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-common/src/main/java/org/apache/shenyu/plugin/ai/common/utils/ResponseBodyCaptureUtils.java: ########## @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.plugin.ai.common.utils; + +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +/** + * Response body capture utils. + */ +public class ResponseBodyCaptureUtils { + + /** + * Capture response body from exchange. + * Note: This method returns an empty string because the response body + * is not available at the time of template assembly. + * The actual response body will be captured in the response decorator. + * + * @param exchange the exchange + * @return the captured response body (empty string) + */ + public static Mono<String> captureResponseBody(final ServerWebExchange exchange) { + // 在响应转换的场景中,响应体还没有被写入,所以返回空字符串 + // 实际的响应体将在 AiResponseTransformerDecorator 中被捕获和处理 Review Comment: The comment is written in Chinese. Since the codebase appears to use English comments throughout, this should be translated to English for consistency. ```suggestion // In the response transformation scenario, the response body has not been written yet, so an empty string is returned // The actual response body will be captured and processed in AiResponseTransformerDecorator ``` ########## shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-common/src/main/java/org/apache/shenyu/plugin/ai/common/utils/ResponseBodyCaptureUtils.java: ########## @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.plugin.ai.common.utils; + +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +/** + * Response body capture utils. + */ +public class ResponseBodyCaptureUtils { + + /** + * Capture response body from exchange. + * Note: This method returns an empty string because the response body + * is not available at the time of template assembly. + * The actual response body will be captured in the response decorator. + * + * @param exchange the exchange + * @return the captured response body (empty string) + */ + public static Mono<String> captureResponseBody(final ServerWebExchange exchange) { + // 在响应转换的场景中,响应体还没有被写入,所以返回空字符串 + // 实际的响应体将在 AiResponseTransformerDecorator 中被捕获和处理 Review Comment: The comment is written in Chinese. Since the codebase appears to use English comments throughout, this should be translated to English for consistency. ```suggestion // In the response transformation scenario, the response body has not been written yet, so an empty string is returned // The actual response body will be captured and processed in AiResponseTransformerDecorator ``` ########## shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-common/src/test/java/org/apache/shenyu/plugin/ai/common/utils/ResponseBodyCaptureUtilsTest.java: ########## @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.plugin.ai.common.utils; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Test for ResponseBodyCaptureUtils. + */ +@ExtendWith(MockitoExtension.class) +class ResponseBodyCaptureUtilsTest { + + @Test + void testCaptureResponseBodyWithNullExchange() { + // 测试空exchange的情况 Review Comment: The comment is written in Chinese. Since the codebase appears to use English comments throughout, this should be translated to English for consistency. ```suggestion // Test the case of a null exchange ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@shenyu.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org