码头和最大内容量 [英] Jetty and max content size

查看:156
本文介绍了码头和最大内容量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Jetty 9.4.8,并且我希望限制可以发布到服务器的数据量.为此,我添加到jetty.xml:

I use Jetty 9.4.8 and i want limits the amount of data that can post to the server. For that i added to jetty.xml:

<Call name="setAttribute">
  <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
  <Arg>10000</Arg>
</Call>

我测试了码头(request-xxlarge.xml-文本文件(20mb)):

I tested jetty like (request-xxlarge.xml - text file(20mb)):

curl -X POST --data @request-xxlarge.xml http://localhost:8080/test -v

结果我得到了

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /test HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 21232818
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
> 
< HTTP/1.1 200 OK
< Content-Length: 4
< Connection: close
< Server: Jetty(9.4.8.v20171121)
< 
* Closing connection 0
POST

服务器处理了请求

已编辑

当Content-Type:应用程序/x-www-form-urlencoded时,服务器返回413.

The server returns 413 when Content-Type: application / x-www-form-urlencoded.

但是,如果我希望它是一个Web服务,并且我想处理Content-Type:application/soap + xml-则maxFormContentSize参数不起作用.

But if I expect it to be a web service and i want to process Content-Type: application / soap + xml - then the maxFormContentSize parameter does not work.

如何限制Web服务的主体大小?

How can I limit the size of the body for a web service?

推荐答案

Jetty可以基于特定的Content-Type值对请求正文内容施加3个限制.

There are 3 limits that Jetty can impose on request body content based on specific Content-Type values.

这是标准的html <form>提交,通过

This is the standard html <form> submission, where the submitted form is accessed via the HttpServletRequest.getParameter(String key) API.

这种请求正文内容可以通过两种不同的方式进行过滤.

This kind of request body content can be filtered in 2 different ways.

org.eclipse.jetty.server.Request.maxFormContentSize-这是对请求正文内容的整体大小(以字节为单位)的限制.

org.eclipse.jetty.server.Request.maxFormContentSize - this is a limit on the overall size (in bytes) of the request body content.

org.eclipse.jetty.server.Request.maxFormKeys-这是对提交的表单的表单密钥总数的限制.

org.eclipse.jetty.server.Request.maxFormKeys - this is a limit on the overall number of form keys of the form being submitted.

上面的2个键需要整数值,并且可以通过以下任何一种技术来设置...

The above 2 keys expect integer values, and can be set in any of the following techniques ...

Server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 100000)

2)作为适用于所有已部署Web应用程序的系统属性

$ java -Dorg.eclipse.jetty.server.Request.maxFormContentSize=100000 \
       -jar /path/to/jetty-home/start.jar

System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "1000000")

3)作为部署的WebAppContext

上的Context参数

在您的${jetty.base}/webapps/<context>.xml中,您可以设置这些值

3) As a Context parameter on the deployed WebAppContext

In your ${jetty.base}/webapps/<context>.xml you can set these values

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
    "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/mycontext</Set>
  <Set name="war"><Property name="jetty.webapps"/>/mycontext.war</Set>

  <Set name="maxFormKeys">100</Set>
  <Set name="maxFormContentSize">202020</Set>
</Configure>

内容类型:multipart/form-data

这也是如上所述的标准表单提交,但是也可以通过

Content-Type: multipart/form-data

This is also a standard form submission as above, but the data can also be accessed via the HttpServletRequest.getPart(String name) APIs.

通过目标Servlet的 @MultipartConfig 值(或<servlet><multipart-config>元素的WEB-INF/web.xml条目)

This kind of data is restricted via the configuration present for the destination Servlet's @MultipartConfig values (or WEB-INF/web.xml entries for the <servlet><multipart-config> elements)

要通过整个请求大小限制这种内容类型,请使用maxRequestSize配置.

To limit this kind of content type by entire request size, use the maxRequestSize configuration.

对于所有其他Content-Type值,servlet规范和Jetty不参与解析或限制大小.

For all other Content-Type values, the servlet spec, and Jetty are not involved in parsing or limiting the size.

如果您使用的是库来处理请求(REST,SOAP等),请检查该库是否具有根据大小或其他原因拒绝请求的机制(例如:格式不正确,缺少预期/必需的数据,等等.

If you are using a library to handle your requests (REST, SOAP, etc) then check with that library to see if it has a mechanism to reject requests based on size, or other reasons (eg: not well-formed, missing expected/required data, etc).

与往常一样,如果您想要一个功能,请随时通过以下位置在Eclipse Jetty问题跟踪器上请求它: https://github.com/eclipse/jetty.project/issues

As always, if you want a feature, feel free to request it on the Eclipse Jetty issue tracker at https://github.com/eclipse/jetty.project/issues

这篇关于码头和最大内容量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆