/** * Set the maximum body size -1 means unlimited * @param bodyLimit the max size * @return reference to this for fluency */ public io.vertx.rxjava.ext.web.handler.BodyHandler setBodyLimit(long bodyLimit) { delegate.setBodyLimit(bodyLimit); return this; }
/** * Set the maximum body size -1 means unlimited * @param bodyLimit the max size * @return reference to this for fluency */ public io.vertx.rxjava.ext.web.handler.BodyHandler setBodyLimit(long bodyLimit) { delegate.setBodyLimit(bodyLimit); return this; }
@Test public void testBodyLimitWithHandleFileUploadsFalse() throws Exception { router.clear(); BodyHandler bodyHandler = BodyHandler.create(false).setBodyLimit(2048); router.route().handler(bodyHandler); Buffer fileData = TestUtils.randomBuffer(4096); router.route().handler(rc -> { rc.response().end(); }); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testFileDeleteOnLargeUpload() throws Exception { String uploadsDirectory = tempUploads.newFolder().getPath(); router.clear(); router.route().handler(BodyHandler.create() .setDeleteUploadedFilesOnEnd(true) .setBodyLimit(10000) .setUploadsDirectory(uploadsDirectory)); router.route().handler(ctx -> { fail(); ctx.fail(500); }); sendFileUploadRequest(TestUtils.randomBuffer(20000), 413, "Request Entity Too Large"); Thread.sleep(100); // wait until file is removed assertEquals(0, vertx.fileSystem().readDirBlocking(uploadsDirectory).size()); }
@Test public void testFileUploadTooBig2() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(20000)); Buffer fileData = TestUtils.randomBuffer(50000); router.route().handler(rc -> fail("Should not be called")); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testFileUploadTooBig() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(20000)); Buffer fileData = TestUtils.randomBuffer(50000); router.route().handler(rc -> fail("Should not be called")); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testBodyTooBig() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(5000)); Buffer buff = TestUtils.randomBuffer(10000); router.route().handler(rc -> fail("Should not be called")); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 413, "Request Entity Too Large", null); }
@Test public void testBodyTooBig2() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(500)); Buffer buff = TestUtils.randomBuffer(1000); router.route().handler(rc -> fail("Should not be called")); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 413, "Request Entity Too Large", null); }
private void addBodyHandler(Router router) { Integer bodyLimit = config.getInteger("body.limit"); router.route().handler(BodyHandler.create().setBodyLimit((isNull(bodyLimit) ? DEFAULT_BODY_LIMIT : bodyLimit) * MB)); }
/** * Creates the router for handling requests. * <p> * This method creates a router instance with a default route limiting the body size of requests to the maximum * payload size set in the <em>config</em> properties. * * @return The newly created router (never {@code null}). */ protected Router createRouter() { final Router router = Router.router(vertx); LOG.info("limiting size of inbound request body to {} bytes", getConfig().getMaxPayloadSize()); router.route() .handler(BodyHandler.create().setBodyLimit(getConfig().getMaxPayloadSize()).setUploadsDirectory(DEFAULT_UPLOADS_DIRECTORY)) .failureHandler(new DefaultFailureHandler()); return router; }
/** * Creates the router for handling requests. * <p> * This method creates a router instance with a default route limiting the body size of requests to the maximum * payload size set in the <em>config</em> properties. * * @return The newly created router (never {@code null}). */ protected Router createRouter() { final Router router = Router.router(vertx); LOG.info("limiting size of inbound request body to {} bytes", getConfig().getMaxPayloadSize()); router.route() .handler(BodyHandler.create().setBodyLimit(getConfig().getMaxPayloadSize()).setUploadsDirectory(DEFAULT_UPLOADS_DIRECTORY)) .failureHandler(new DefaultFailureHandler()); return router; }
/** * Creates the router for handling requests. * <p> * This method creates a router instance with the following routes: * <ol> * <li>A default route limiting the body size of requests to the maximum payload size set in the <em>config</em> properties.</li> * </ol> * * @return The newly created router (never {@code null}). */ protected Router createRouter() { final Router router = Router.router(vertx); LOG.info("limiting size of inbound request body to {} bytes", getConfig().getMaxPayloadSize()); router.route().handler(BodyHandler.create(DEFAULT_UPLOADS_DIRECTORY).setBodyLimit(getConfig().getMaxPayloadSize())); addTracingHandler(router, -5); // add default handler for failed routes router.route().order(-1).failureHandler(new DefaultFailureHandler()); return router; }
/** * Creates the router for handling requests. * <p> * This method creates a router instance with the following routes: * <ol> * <li>A default route limiting the body size of requests to the maximum payload size set in the <em>config</em> properties.</li> * </ol> * * @return The newly created router (never {@code null}). */ protected Router createRouter() { final Router router = Router.router(vertx); LOG.info("limiting size of inbound request body to {} bytes", getConfig().getMaxPayloadSize()); router.route().handler(BodyHandler.create(DEFAULT_UPLOADS_DIRECTORY).setBodyLimit(getConfig().getMaxPayloadSize())); addTracingHandler(router, -5); // add default handler for failed routes router.route().order(-1).failureHandler(new DefaultFailureHandler()); return router; }
@Override public void addRoutes(final Router router) { final String path = String.format("/%s", TenantConstants.TENANT_ENDPOINT); final BodyHandler bodyHandler = BodyHandler.create(); bodyHandler.setBodyLimit(config.getMaxPayloadSize()); // ADD tenant router.post(path).handler(bodyHandler); router.post(path).handler(this::extractRequiredJsonPayload); router.post(path).handler(this::checkPayloadForTenantId); router.post(path).handler(this::addTenant); final String pathWithTenant = String.format("/%s/:%s", TenantConstants.TENANT_ENDPOINT, PARAM_TENANT_ID); // GET tenant router.get(pathWithTenant).handler(this::getTenant); // UPDATE tenant router.put(pathWithTenant).handler(bodyHandler); router.put(pathWithTenant).handler(this::extractRequiredJsonPayload); router.put(pathWithTenant).handler(this::updateTenant); // REMOVE tenant router.delete(pathWithTenant).handler(this::removeTenant); }
@Test public void testBodyLimitWithHandleFileUploadsFalse() throws Exception { router.clear(); BodyHandler bodyHandler = BodyHandler.create(false).setBodyLimit(2048); router.route().handler(bodyHandler); Buffer fileData = TestUtils.randomBuffer(4096); router.route().handler(rc -> { rc.response().end(); }); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testFileDeleteOnLargeUpload() throws Exception { String uploadsDirectory = tempUploads.newFolder().getPath(); router.clear(); router.route().handler(BodyHandler.create() .setDeleteUploadedFilesOnEnd(true) .setBodyLimit(10000) .setUploadsDirectory(uploadsDirectory)); router.route().handler(ctx -> { fail(); ctx.fail(500); }); sendFileUploadRequest(TestUtils.randomBuffer(20000), 413, "Request Entity Too Large"); Thread.sleep(100); // wait until file is removed assertEquals(0, vertx.fileSystem().readDirBlocking(uploadsDirectory).size()); }
@Test public void testFileUploadTooBig() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(20000)); Buffer fileData = TestUtils.randomBuffer(50000); router.route().handler(rc -> fail("Should not be called")); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testFileUploadTooBig2() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(20000)); Buffer fileData = TestUtils.randomBuffer(50000); router.route().handler(rc -> fail("Should not be called")); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testBodyTooBig() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(5000)); Buffer buff = TestUtils.randomBuffer(10000); router.route().handler(rc -> fail("Should not be called")); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 413, "Request Entity Too Large", null); }
@Test public void testBodyTooBig2() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(500)); Buffer buff = TestUtils.randomBuffer(1000); router.route().handler(rc -> fail("Should not be called")); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 413, "Request Entity Too Large", null); }