Caideyipi commented on code in PR #17481:
URL: https://github.com/apache/iotdb/pull/17481#discussion_r3370697772


##########
external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/RequestSizeLimitFilter.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iotdb.rest.protocol.filter;
+
+import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+@Provider
+@PreMatching
+public class RequestSizeLimitFilter implements ContainerRequestFilter {
+
+  @Override
+  public void filter(ContainerRequestContext requestContext) {
+    long maxBodySize =
+        
IoTDBRestServiceDescriptor.getInstance().getConfig().getRestMaxRequestBodySizeInBytes();
+    if (maxBodySize <= 0) {
+      return;
+    }
+
+    int contentLength = requestContext.getLength();
+    if (contentLength > maxBodySize) {
+      requestContext.abortWith(buildPayloadTooLargeResponse(maxBodySize));
+      return;
+    }
+
+    requestContext.setEntityStream(
+        new LimitedInputStream(requestContext.getEntityStream(), maxBodySize));
+  }
+
+  private static Response buildPayloadTooLargeResponse(long maxBodySize) {
+    return Response.status(413)
+        .type(MediaType.TEXT_PLAIN_TYPE)

Review Comment:
   `RequestSizeLimitFilter` returns this 413 as `text/plain`, but the filter 
runs before the resource methods and the per-version `ExceptionHandler`. The 
new row/column/value limit path returns a JSON `ExecutionStatus` with code 413, 
and the REST OpenAPI/clients/tests consume REST responses as JSON 
`ExecutionStatus`.
   
   This makes oversized request bodies the one limit-failure path that can 
break clients which parse REST errors as JSON. Could we return 
`application/json` here with an `ExecutionStatus` entity, e.g. `{code: 413, 
message: ...}`, and add coverage for both the `Content-Length` abort path and 
the streamed/chunked overflow path?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to