【问题标题】:Why does Spring not support RequestMethod.LINK?为什么 Spring 不支持 RequestMethod.LINK?
【发布时间】:2019-07-04 02:27:32
【问题描述】:

为什么 Spring 不支持 RequestMethod.LINK?如何使用 @RequestMapping 或其他选项通过 LINK 方法捕获查询?

【问题讨论】:

  • 如果您提供代码sn-p会更好。还要问具体问题而不是理论。
  • 以前从未听说过这样的请求方法,而且互联网标准(tools.ietf.org/html/rfc7231,第 4.3 章方法定义)对此一无所知。您是从哪里听到/读到这种新的请求方法的?
  • 截图邮递员 - prnt.sc/mj4x9z
  • 我在 1997 年 1 月的 RFC 2068 (tools.ietf.org/html/rfc2068#section-19.6.1.2) 中发现了对 LINK 请求方法的模糊引用。RFC 2616(1999 年 6 月的tools.ietf.org/html/rfc2616)废弃了 RFC 2068 并删除了 LINK请求方法。似乎 LINK 请求方法从来没有受到太大的关注——我怀疑你会找到任何可以发送这个请求方法的客户端(除了 PostMan)。所以问题还是:需要支持这种请求方式吗?

标签: java spring spring-boot http


【解决方案1】:

决定

@RequestMapping("/test")
public int anotherMethods(HttpServletRequest request) {
    if (request.getMethod().equals("LINK")) {
        logger.info("LINK METHOD");
    }
    if (request.getMethod().equals("UNLINK")) {
        logger.info("UNLINK METHOD");
    }
    return HttpStatus.OK.value();
}

并添加

public class SecurityConfig extends WebSecurityConfigurerAdapter {

...
    @Override
    public void configure(WebSecurity web) throws Exception {
        super.configure(web);
        web.httpFirewall(allowHttpMethodsFirewall());
    }

    @Bean
    public HttpFirewall allowHttpMethodsFirewall() {
        StrictHttpFirewall firewall = new StrictHttpFirewall();
        firewall.setAllowedHttpMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "LINK", "UNLINK"));
        return firewall;
    }

}

【讨论】:

    猜你喜欢
    • 2018-08-09
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2011-03-17
    • 2018-07-21
    • 2013-01-04
    • 2017-10-07
    • 2018-08-24
    相关资源
    最近更新 更多