[GitHub] [shenyu] yuejq commented on issue #4558: [BUG] shenyu.file.maxSize config</span></a></span> </h1> <p class="darkgray font13"> <span class="sender pipe"><a href="/search?l=notifications@shenyu.apache.org&q=from:%22via+GitHub%22" rel="nofollow"><span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">via GitHub</span></span></a></span> <span class="date"><a href="/search?l=notifications@shenyu.apache.org&q=date:20230806" rel="nofollow">Sun, 06 Aug 2023 03:49:32 -0700</a></span> </p> </div> <div itemprop="articleBody" class="msgBody"> <!--X-Body-of-Message--> <pre> yuejq commented on issue #4558: URL: <a rel="nofollow" href="https://github.com/apache/shenyu/issues/4558#issuecomment-1666812898">https://github.com/apache/shenyu/issues/4558#issuecomment-1666812898</a></pre><pre> `public class FileSizeFilter implements WebFilter { private static final int BYTES_PER_MB = 1024 * 1024; private final int fileMaxSize; @Override @NonNull public Mono<Void> filter(@NonNull final ServerWebExchange exchange, @NonNull final WebFilterChain chain) { MediaType mediaType = exchange.getRequest().getHeaders().getContentType(); if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(mediaType)) { ServerRequest serverRequest = ServerRequest.create(exchange, messageReaders); return serverRequest.bodyToMono(DataBuffer.class) .flatMap(dataBuffer -> { **_if (dataBuffer.capacity() > BYTES_PER_MB * fileMaxSize) {_** ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(HttpStatus.BAD_REQUEST); Object error = ShenyuResultWrap.error(exchange, ShenyuResultEnum.PAYLOAD_TOO_LARGE); LOG.info("The file size exceeds the limit. The actual size is {}M , response:{}", dataBuffer.capacity() / BYTES_PER_MB, error); return WebFluxResultUtils.result(exchange, error); } BodyInserter<Mono<DataBuffer>, ReactiveHttpOutputMessage> bodyInsert = BodyInserters.fromPublisher(Mono.just(dataBuffer), DataBuffer.class); HttpHeaders headers = new HttpHeaders(); headers.putAll(exchange.getRequest().getHeaders()); headers.remove(HttpHeaders.CONTENT_LENGTH); CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage( exchange, headers); return bodyInsert.insert(outputMessage, new BodyInserterContext()) .then(Mono.defer(() -> { ServerHttpRequest decorator = decorate(exchange, outputMessage); return chain.filter(exchange.mutate().request(decorator).build()); })).doFinally(signalType -> DataBufferUtils.release(dataBuffer)) .onErrorResume((Function<Throwable, Mono<Void>>) throwable -> ResponseUtils.release(outputMessage, throwable)); }); } return chain.filter(exchange); } }` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@shenyu.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org </pre> </div> <div class="msgButtons margintopdouble"> <ul class="overflow"> <li class="msgButtonItems"><a class="button buttonleft " accesskey="p" href="msg25408.html">Previous message</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="c" href="thrd11.html#26841">View by thread</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="i" href="maillist.html#26841">View by date</a></li> <li class="msgButtonItems textalignright"><a class="button buttonright " accesskey="n" href="msg24736.html">Next message</a></li> </ul> </div> <a name="tslice"></a> <div class="tSliceList margintopdouble"> <ul class="icons monospace"> <li class="icons-email"><span class="subject"><a href="msg24730.html">[GitHub] [shenyu] yuejq opened a new issue, #4558: [BUG] <ti...</a></span> <span class="sender italic">via GitHub</span></li> <li><ul> <li class="icons-email"><span class="subject"><a href="msg24734.html">[GitHub] [shenyu] comeCU commented on issue #4558: [BUG] &...</a></span> <span class="sender italic">via GitHub</span></li> <li class="icons-email"><span class="subject"><a href="msg25341.html">[GitHub] [shenyu] peng-heng commented on issue #4558: [BUG...</a></span> <span class="sender italic">via GitHub</span></li> <li class="icons-email"><span class="subject"><a href="msg25408.html">[GitHub] [shenyu] yuejq commented on issue #4558: [BUG] &l...</a></span> <span class="sender italic">via GitHub</span></li> <li class="icons-email tSliceCur"><span class="subject">[GitHub] [shenyu] yuejq commented on issue #4558: [BUG] &l...</span> <span class="sender italic">via GitHub</span></li> </ul> </ul> </div> <div class="overflow msgActions margintopdouble"> <div class="msgReply" > <h2> Reply via email to </h2> <form method="POST" action="/mailto.php"> <input type="hidden" name="subject" value="[GitHub] [shenyu] yuejq commented on issue #4558: [BUG] <title> shenyu.file.maxSize config"> <input type="hidden" name="msgid" value="I_kwDOCGCHjs5jfWTL-da714eab-b22d-4042-b5de-ef36a8aad8b1@gitbox.apache.org"> <input type="hidden" name="relpath" value="notifications@shenyu.apache.org/msg26841.html"> <input type="submit" value=" via GitHub "> </form> </div> </div> </div> <div class="aside" role="complementary"> <div class="logo"> <a href="/"><img src="/logo.png" width=247 height=88 alt="The Mail Archive"></a> </div> <form class="overflow" action="/search" method="get"> <input type="hidden" name="l" value="notifications@shenyu.apache.org"> <label class="hidden" for="q">Search the site</label> <input class="submittext" type="text" id="q" name="q" placeholder="Search notifications"> <input class="submitbutton" name="submit" type="image" src="/submit.png" alt="Submit"> </form> <div class="nav margintop" id="nav" role="navigation"> <ul class="icons font16"> <li class="icons-home"><a href="/">The Mail Archive home</a></li> <li class="icons-list"><a href="/notifications@shenyu.apache.org/">notifications - all messages</a></li> <li class="icons-about"><a href="/notifications@shenyu.apache.org/info.html">notifications - about the list</a></li> <li class="icons-expand"><a href="/search?l=notifications@shenyu.apache.org&q=subject:%22%5C%5BGitHub%5C%5D+%5C%5Bshenyu%5C%5D+yuejq+commented+on+issue+%234558%5C%3A+%5C%5BBUG%5C%5D+%3Ctitle%3E+shenyu.file.maxSize+config%22&o=newest&f=1" title="e" id="e">Expand</a></li> <li class="icons-prev"><a href="msg25408.html" title="p">Previous message</a></li> <li class="icons-next"><a href="msg24736.html" title="n">Next message</a></li> </ul> </div> <div class="listlogo margintopdouble"> </div> <div class="margintopdouble"> </div> </div> </div> <div class="footer" role="contentinfo"> <ul> <li><a href="/">The Mail Archive home</a></li> <li><a href="/faq.html#newlist">Add your mailing list</a></li> <li><a href="/faq.html">FAQ</a></li> <li><a href="/faq.html#support">Support</a></li> <li><a href="/faq.html#privacy">Privacy</a></li> <li class="darkgray">I_kwDOCGCHjs5jfWTL-da714eab-b22d-4042-b5de-ef36a8aad8b1@gitbox.apache.org</li> </ul> </div> </body> </html> <script>(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'9cfe0281af567089',t:'MTc3MTQyMjc5Nw=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script>