-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hotfix: remove problematic RequestBodyCachingFilter temporarily
- Loading branch information
1 parent
c80ad4c
commit 8b4938c
Showing
1 changed file
with
46 additions
and
46 deletions.
There are no files selected for viewing
92 changes: 46 additions & 46 deletions
92
photo-service/src/main/java/kr/mafoo/photo/config/RequestBodyCachingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// }); | ||
// } | ||
//} | ||
// |