Skip to content

Commit

Permalink
hotfix: remove problematic RequestBodyCachingFilter temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
gmkim20713 committed Oct 26, 2024
1 parent c80ad4c commit 8b4938c
Showing 1 changed file with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package kr.mafoo.photo.config;

import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebExchangeDecorator;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Component
public class RequestBodyCachingFilter implements WebFilter {

// TODO: 추후 정리 필요

@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return DataBufferUtils.join(exchange.getRequest().getBody())
.flatMap(dataBuffer -> {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);

ServerHttpRequestDecorator decoratedRequest = new ServerHttpRequestDecorator(exchange.getRequest()) {
@Override
public Flux<DataBuffer> getBody() {
return Flux.just(exchange.getResponse().bufferFactory().wrap(bytes));
}
};

ServerWebExchangeDecorator decoratedExchange = new ServerWebExchangeDecorator(exchange) {
@Override
public ServerHttpRequest getRequest() {
return decoratedRequest;
}
};

return chain.filter(decoratedExchange);
});
}
}

//package kr.mafoo.photo.config;
//
//import org.springframework.core.io.buffer.DataBuffer;
//import org.springframework.core.io.buffer.DataBufferUtils;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import org.springframework.web.server.ServerWebExchangeDecorator;
//import org.springframework.web.server.WebFilter;
//import org.springframework.web.server.WebFilterChain;
//import reactor.core.publisher.Flux;
//import reactor.core.publisher.Mono;
//
//@Component
//public class RequestBodyCachingFilter implements WebFilter {
//
// // TODO: 추후 정리 필요
//
// @Override
// public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
// return DataBufferUtils.join(exchange.getRequest().getBody())
// .flatMap(dataBuffer -> {
// byte[] bytes = new byte[dataBuffer.readableByteCount()];
// dataBuffer.read(bytes);
// DataBufferUtils.release(dataBuffer);
//
// ServerHttpRequestDecorator decoratedRequest = new ServerHttpRequestDecorator(exchange.getRequest()) {
// @Override
// public Flux<DataBuffer> getBody() {
// return Flux.just(exchange.getResponse().bufferFactory().wrap(bytes));
// }
// };
//
// ServerWebExchangeDecorator decoratedExchange = new ServerWebExchangeDecorator(exchange) {
// @Override
// public ServerHttpRequest getRequest() {
// return decoratedRequest;
// }
// };
//
// return chain.filter(decoratedExchange);
// });
// }
//}
//

0 comments on commit 8b4938c

Please sign in to comment.