1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

add content-type for sentinel spring cloud gateway fallback

This commit is contained in:
fangjian0423 2019-05-27 21:11:21 +08:00
parent d59219fd33
commit f1a269d7fa
2 changed files with 15 additions and 1 deletions

View File

@ -17,6 +17,7 @@
package org.springframework.cloud.alibaba.sentinel.gateway; package org.springframework.cloud.alibaba.sentinel.gateway;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
/** /**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a> * @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
@ -40,6 +41,10 @@ public class FallbackProperties {
* Response Status for `response` mode. * Response Status for `response` mode.
*/ */
private Integer responseStatus = HttpStatus.TOO_MANY_REQUESTS.value(); private Integer responseStatus = HttpStatus.TOO_MANY_REQUESTS.value();
/**
* Content-Type for `response` mode.
*/
private String contentType = MediaType.APPLICATION_JSON_UTF8.toString();
public String getMode() { public String getMode() {
return mode; return mode;
@ -77,4 +82,12 @@ public class FallbackProperties {
return this; return this;
} }
public String getContentType() {
return contentType;
}
public FallbackProperties setContentType(String contentType) {
this.contentType = contentType;
return this;
}
} }

View File

@ -111,7 +111,8 @@ public class SentinelSCGAutoConfiguration {
Throwable t) { Throwable t) {
return ServerResponse return ServerResponse
.status(fallbackProperties.getResponseStatus()) .status(fallbackProperties.getResponseStatus())
.contentType(MediaType.APPLICATION_JSON_UTF8) .contentType(MediaType
.valueOf(fallbackProperties.getContentType()))
.body(fromObject(fallbackProperties.getResponseBody())); .body(fromObject(fallbackProperties.getResponseBody()));
} }
}); });