This commit is contained in:
hongqiaowei
2022-02-14 18:11:15 +08:00
parent e7efe0eb32
commit aac784e045

View File

@@ -275,30 +275,42 @@ public abstract class WebUtils {
} }
public static Mono<Void> response(ServerHttpResponse clientResp, HttpStatus status, HttpHeaders headers, ByteBuffer body) { public static Mono<Void> response(ServerHttpResponse clientResp, HttpStatus status, HttpHeaders headers, ByteBuffer body) {
DataBuffer dataBuffer = clientResp.bufferFactory().wrap(body); DataBuffer dataBuffer = null;
if (body != null) {
dataBuffer = clientResp.bufferFactory().wrap(body);
}
return response(clientResp, status, headers, dataBuffer); return response(clientResp, status, headers, dataBuffer);
} }
public static Mono<Void> response(ServerHttpResponse clientResp, HttpStatus status, HttpHeaders headers, byte[] body) { public static Mono<Void> response(ServerHttpResponse clientResp, HttpStatus status, HttpHeaders headers, byte[] body) {
DataBuffer dataBuffer = clientResp.bufferFactory().wrap(body); DataBuffer dataBuffer = null;
if (body != null) {
dataBuffer = clientResp.bufferFactory().wrap(body);
}
return response(clientResp, status, headers, dataBuffer); return response(clientResp, status, headers, dataBuffer);
} }
public static Mono<Void> response(ServerHttpResponse clientResp, HttpStatus status, HttpHeaders headers, String body) { public static Mono<Void> response(ServerHttpResponse clientResp, HttpStatus status, HttpHeaders headers, String body) {
DataBuffer dataBuffer = clientResp.bufferFactory().wrap(body.getBytes(StandardCharsets.UTF_8)); DataBuffer dataBuffer = null;
if (body != null) {
dataBuffer = clientResp.bufferFactory().wrap(body.getBytes(StandardCharsets.UTF_8));
}
return response(clientResp, status, headers, dataBuffer); return response(clientResp, status, headers, dataBuffer);
} }
public static Mono responseJson(ServerWebExchange exchange, HttpStatus status, HttpHeaders headers, Object object) { public static Mono<Void> responseJson(ServerWebExchange exchange, HttpStatus status, HttpHeaders headers, Object body) {
if (headers == null) { if (headers == null) {
headers = new HttpHeaders(); headers = new HttpHeaders();
} }
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
byte[] bytes = JacksonUtils.writeValueAsBytes(object); byte[] bytes = null;
if (body != null) {
bytes = JacksonUtils.writeValueAsBytes(body);
}
return response(exchange.getResponse(), status, headers, bytes); return response(exchange.getResponse(), status, headers, bytes);
} }
public static Mono responseJson(ServerWebExchange exchange, HttpStatus status, HttpHeaders headers, String json) { public static Mono<Void> responseJson(ServerWebExchange exchange, HttpStatus status, HttpHeaders headers, String json) {
if (headers == null) { if (headers == null) {
headers = new HttpHeaders(); headers = new HttpHeaders();
} }