开箱即用,Spring Boot 符合 RFC7230 section-3.2.4当 header 无效时返回 400,例如:
curl -v -H "Authorization : Basic xxxx" $SOME_URL
以下是详细 curl 输出的相关摘录:
* HTTP 1.0, assume close after body
< HTTP/1.0 400 Bad Request
< content-length: 0
< connection: close
<
* Closing connection 0
(没有正文,没有解释)
冒号前禁止使用额外的空格。不幸的是,我似乎无法捕获该异常并为其提供文本正文。请求不会出现在 WebFilter 中,异常也不会被 AbstractErrorWebExceptionHandler 捕获。关于如何处理这种情况有什么建议吗?
最佳答案
虽然我不确定您如何保护端点,但您可能会对以下链接感兴趣https://www.baeldung.com/spring-security-custom-authentication-failure-handler 。
关于java - 当 HTTP header 无效(包含空格)时提供自定义错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61633425/