|
1 | 1 | package org.lowcoder.api.framework.filter;
|
2 | 2 |
|
3 |
| -import jakarta.annotation.PostConstruct; |
4 |
| -import lombok.extern.slf4j.Slf4j; |
5 |
| -import org.apache.commons.io.FileUtils; |
| 3 | +import static org.lowcoder.api.framework.filter.FilterOrder.QUERY_EXECUTE_HTTP_BODY_SIZE; |
| 4 | +import static org.lowcoder.sdk.exception.BizError.EXCEED_QUERY_REQUEST_SIZE; |
| 5 | +import static org.lowcoder.sdk.exception.BizError.EXCEED_QUERY_RESPONSE_SIZE; |
| 6 | + |
| 7 | +import java.util.concurrent.atomic.AtomicLong; |
| 8 | + |
| 9 | +import javax.annotation.Nonnull; |
| 10 | + |
6 | 11 | import org.lowcoder.infra.constant.NewUrl;
|
7 | 12 | import org.lowcoder.infra.constant.Url;
|
8 | 13 | import org.lowcoder.sdk.config.CommonConfig;
|
|
19 | 24 | import org.springframework.http.server.reactive.ServerHttpResponse;
|
20 | 25 | import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
|
21 | 26 | import org.springframework.stereotype.Component;
|
| 27 | +import org.springframework.util.unit.DataSize; |
22 | 28 | import org.springframework.web.server.ServerWebExchange;
|
23 | 29 | import org.springframework.web.server.WebFilter;
|
24 | 30 | import org.springframework.web.server.WebFilterChain;
|
| 31 | + |
| 32 | +import jakarta.annotation.PostConstruct; |
| 33 | +import lombok.extern.slf4j.Slf4j; |
25 | 34 | import reactor.core.publisher.Flux;
|
26 | 35 | import reactor.core.publisher.Mono;
|
27 | 36 |
|
28 |
| -import javax.annotation.Nonnull; |
29 |
| -import java.util.concurrent.atomic.AtomicLong; |
30 |
| - |
31 |
| -import static org.lowcoder.api.framework.filter.FilterOrder.QUERY_EXECUTE_HTTP_BODY_SIZE; |
32 |
| -import static org.lowcoder.sdk.exception.BizError.EXCEED_QUERY_REQUEST_SIZE; |
33 |
| -import static org.lowcoder.sdk.exception.BizError.EXCEED_QUERY_RESPONSE_SIZE; |
34 |
| - |
35 | 37 | /**
|
36 | 38 | * check query request and response size
|
37 | 39 | */
|
@@ -60,11 +62,13 @@ public Mono<Void> filter(@Nonnull ServerWebExchange exchange, @Nonnull WebFilter
|
60 | 62 | // check query api
|
61 | 63 | if (path.startsWith(NewUrl.QUERY_URL) || path.startsWith(Url.QUERY_URL)) {
|
62 | 64 |
|
63 |
| - long maxRequestSize = configInstance.ofLong("maxRequestSize", |
64 |
| - commonConfig.getMaxQueryRequestSizeInMb() * FileUtils.ONE_MB); |
65 |
| - long maxResponseSize = configInstance.ofLong("maxResponseSize", |
66 |
| - commonConfig.getMaxQueryResponseSizeInMb() * FileUtils.ONE_MB); |
| 65 | + String maxSize = configInstance.ofString("maxRequestSize", commonConfig.getMaxQueryRequestSize()); |
| 66 | + long maxRequestSize = DataSize.parse(maxSize).toBytes(); |
| 67 | + maxSize = configInstance.ofString("maxResponseSize", commonConfig.getMaxQueryResponseSize()); |
| 68 | + long maxResponseSize = DataSize.parse(maxSize).toBytes(); |
67 | 69 |
|
| 70 | + log.info("Setting up maximum query request size to: {} bytes", maxRequestSize); |
| 71 | + log.info("Setting up maximum query response size to: {} bytes", maxResponseSize); |
68 | 72 | ServerWebExchange newServerWebExchange = exchange.mutate()
|
69 | 73 | .request(new CustomServerHttpRequestDecorator(exchange.getRequest(), maxRequestSize))
|
70 | 74 | .response(new CustomServerHttpResponseDecorator(exchange.getResponse(), maxResponseSize))
|
@@ -126,4 +130,5 @@ public Mono<Void> writeWith(@Nonnull Publisher<? extends DataBuffer> body) {
|
126 | 130 | }));
|
127 | 131 | }
|
128 | 132 | }
|
| 133 | + |
129 | 134 | }
|
0 commit comments