The HTTP header line [connection : Keep-alive] does not conform to RFC 7230 and has been ignored

在测试一个程序的时候,出现了“The HTTP header line [connection : Keep-alive] does not conform to RFC 7230 and has been ignored”这个错误;经搜索关键字 RFC 7230发现是tomcat高版本中,严格按照规范解析。

百度了一下解决方案, 都是千篇一律,或许最初的作者是解决了问题的,但是对于我这一版本(spring-boot-starter-tomcat:2.3.3.Release,即tomcat版本为9.0.37)无效,常见搜索的springBoot2.x的解决方案如下:

@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]"));
        return factory;
}

原文链接如下:
https://www.freesion.com/article/2397892175/

最终解决方案如下:

package net.dlet.dhdemo.configure;

import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 配置转义字符,解决当请求路径中特殊字符,解决高版本Tomcat对接口参数限制字符,解析失败从而出现RFC7230、RFC3986问题
 * @PackageName: net.dlet.dhdemo.configure
 * @Name: RF7230
 * @Author: cure
 * @CreateDate: 2020/09/06 00:30
 * @ModifyUser:
 * @ModifyDate:
 * @ModifyDesc: 修改内容
 * @DayNameFull: 星期日
 * @ProjectName: dhdemo
 * @Version: 1.0
 **/
@Configuration
public class RFC7230 {

    /**
     * 解决Tomcat RFC7230问题
     * @return
     */
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
            connector.setProperty("relaxedQueryChars", "|{}[](),/:;<=>?@[\\]{}\\");
            connector.setProperty("relaxedPathChars", "|{}[](),/:;<=>?@[\\]{}\\");
            connector.setProperty("rejectIllegalHeader", "false");
        });

        return factory;
    }
}

 

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值