在SpringBoot2设置Max-HTTP-Header-Size

1.介绍

默认情况下,Spring Boot Web 应用程序包括一个预配置的嵌入式 Web 服务器。 但是,在某些情况下,希望修改默认配置以满足自定义要求。

如何在 Spring Boot 2.x 应用程序的 application.properties 文件中为请求标头设置和使用 max-http-header-size 属性。

2. Max-HTTP-Header-Size

Spring Boot 支持 Tomcat、Undertow 和 Jetty 作为嵌入式服务器。 通常,在 Spring Boot 应用程序中的 application.properties 文件或 application.yaml 文件中编写服务器配置。

大多数 Web 服务器都有自己的一组 HTTP 请求标头大小限制。 HTTP 标头值受服务器实现的限制。 在 Spring Boot 应用程序中,最大 HTTP 标头大小是使用 server.max-http-header-size 配置的。

Tomcat和Jetty的实际默认值为8kB,Undertow的默认值为1MB

要修改最大 HTTP 标头大小,将该属性添加到 application.properties 文件中:

server.max-http-header-size=20000

同样对于 application.yaml 格式:

server:
    max-http-header-size: 20000

从 Spring Boot 2.1 开始,将使用 DataSize 可解析值:

server.max-http-header-size=10KB

3.请求头太大

假设发送的请求的总 HTTP 标头大小大于 max-http-header-size 值。 服务器以“400 Bad request”错误拒绝请求(java.lang.IllegalArgumentException: Request header is too large)。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/niugang0920/article/details/119680412