重复使用BodyHandler实例
我正在尝试创建类似的内容,
router.route("foo").handler(BodyHandler.create().setBodyLimit(1024*1024))
router.route("bar").handler(BodyHandler.create().setBodyLimit(1024*1024))
router.route("baz").handler(BodyHandler.create().setBodyLimit(1024*1024))
可以调用bodyhandler.create()。setBodyLimit(1024*1024)
在应用程序中仅一次,然后在我需要的地方重复使用它吗?
I'm trying to create something like
router.route("foo").handler(BodyHandler.create().setBodyLimit(1024*1024))
router.route("bar").handler(BodyHandler.create().setBodyLimit(1024*1024))
router.route("baz").handler(BodyHandler.create().setBodyLimit(1024*1024))
Would it be ok to call BodyHandler.create().setBodyLimit(1024*1024)
only once in the app, and reuse it all over the place I need it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,您应该能够在多个路由之间共享
bodyhandler
。实际上,通常通过在所有路线上设置它来共享它,正如另一个答案中正确指出的那样。您可以看一下代码,并发现它不会突变内部任何东西,因此应该是安全的。
From what I can tell, you should be able to share
BodyHandler
between multiple routes. In fact, it is usually shared by setting it on all routes, as was correctly pointed out in another answer.You can take a look at the code and see that it doesn't mutate anything internaly, so should be safe.
是的,您可以重新使用它。但是,根据问题中提供的内容,可以定义一个全球的BodyHandler:这可能是有道理的:
Yes, you can re-use it. But it might make sense, according to what is provided in the question, to define a global BodyHandler: