This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 97f488b [type: refactor] optimize content-type. (#2713)
97f488b is described below
commit 97f488b6eadbbf5fd2cb0e640fdf4ec8c181e8d9
Author: Qicz <[email protected]>
AuthorDate: Wed Jan 5 22:22:56 2022 +0800
[type: refactor] optimize content-type. (#2713)
---
.../java/org/apache/shenyu/plugin/api/result/ShenyuResult.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git
a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java
b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java
index 9da7919..bd66073 100644
---
a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java
+++
b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java
@@ -17,11 +17,15 @@
package org.apache.shenyu.plugin.api.result;
+import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.utils.JsonUtils;
import org.apache.shenyu.common.utils.ObjectTypeUtils;
import org.springframework.http.MediaType;
+import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.server.ServerWebExchange;
+import java.util.Objects;
+
/**
* The interface shenyu result.
*/
@@ -62,6 +66,10 @@ public interface ShenyuResult<T> {
* @return the context type
*/
default MediaType contentType(ServerWebExchange exchange, Object
formatted) {
+ final ClientResponse clientResponse =
exchange.getAttribute(Constants.CLIENT_RESPONSE_ATTR);
+ if (Objects.nonNull(clientResponse) &&
clientResponse.headers().contentType().isPresent()) {
+ return clientResponse.headers().contentType().get();
+ }
return MediaType.APPLICATION_JSON;
}