[英]Configure Javalin (Jetty) max request size (414 URI too long)
How do you configure Javalin to change the max request size, specifically the config to increase the max size of the query parameters on the request (avoiding 414 URI too long
)?如何配置 Javalin 以更改最大请求大小,特别是配置以增加请求中查询参数的最大大小(避免
414 URI too long
)?
I get 414 URI is too long
when I exceed what looks like a default size of 8KB so would like to configure my Javalin server to increase that slightly.当我超过 8KB 的默认大小时,我得到
414 URI is too long
因此我想配置我的 Javalin 服务器以稍微增加它。
I think it uses Jetty under the hood which has a HttpConfiguration.requestHeaderSize
variable that may control it.我认为它在引擎盖下使用 Jetty,它有一个
HttpConfiguration.requestHeaderSize
变量可以控制它。 Or there's a HttpParser._maxHeaderBytes
which is checked before throwing the URI_TOO_LONG_414
exception.或者在抛出
HttpParser._maxHeaderBytes
异常之前检查URI_TOO_LONG_414
。
I can't see how it can all be wired up...我看不出它是如何连接起来的……
Only change the HttpConfiguration
, it will inform the HttpParser
.只改变
HttpConfiguration
,它会通知HttpParser
。
You should be leery of doing this because...你应该谨慎地这样做,因为......
Also, depending on what technology Javalin is using, you might need to also increase the ContextHandler
maxFormContentSize
and/or maxFormKeys
.此外,根据 Javalin 使用的技术,您可能还需要增加
ContextHandler
maxFormContentSize
和/或maxFormKeys
。
If you have reached this need, it screams of abuse of the HTTP spec, you should investigate moving to a traditional HTTP POST with Content-Type: application/x-www-form-urlencoded
instead.如果你已经达到了这个需求,它尖叫着滥用 HTTP 规范,你应该调查转向传统的 HTTP POST,
Content-Type: application/x-www-form-urlencoded
。
Bearing in mind all the advice and warnings listed here ... Assuming you have Javalin defined as follows in your main
method:请牢记此处列出的所有建议和警告...假设您在
main
方法中按如下方式定义了 Javalin:
Javalin app = Javalin.create(config -> {
config.jetty.server(MyJetty::create);
}).start();
Then you can create MyJetty
to customize this and any other settings you may want to use.然后您可以创建
MyJetty
来自定义此设置以及您可能想要使用的任何其他设置。
A very basic example:一个非常基本的例子:
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
public class MyJetty {
public static Server create() {
Server server = new Server();
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setRequestHeaderSize(8192); // use your value here
HttpConnectionFactory httpCF = new HttpConnectionFactory(httpConfiguration);
ServerConnector httpConnector = new ServerConnector(server, httpCF);
httpConnector.setPort(8080); // use your port here
server.addConnector(httpConnector);
return server;
}
}
This only sets up a simple insecure HTTP connection - but shows one way to change the HttpConfiguration
value for Javalin.这只设置了一个简单的不安全的 HTTP 连接 - 但显示了一种更改 Javalin 的
HttpConfiguration
值的方法。 You can use the same approach for other connectors you may want to configure, including ones using SSL/TLS.您可以对可能想要配置的其他连接器使用相同的方法,包括使用 SSL/TLS 的连接器。
I am assuming the latest version of Javalin (version 5) since there were some syntax changes from Javalin 4 to 5 - and also the version of Jetty changed from 9 to 11.我假设是最新版本的 Javalin(版本 5),因为从 Javalin 4 到 5 有一些语法变化——而且 Jetty 的版本也从 9 到 11。
If you are using Javalin 4, the config
syntax is a bit different:如果您使用的是 Javalin 4,则
config
语法有点不同:
config.server(MyJetty::create);
But I don't think the Jetty code changes (for this specific setting, at least).但我认为 Jetty 代码不会改变(至少对于这个特定设置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.