RESTeasy 和 X-HTTP-Method-Override

发布于 2025-01-01 06:11:35 字数 304 浏览 1 评论 0 原文

有没有什么方法支持 X-HTTP-Method-Override 请求头 (自动/透明地)在 RESTeasy 中?

这会 使支持无法发送 PUT/DELETE 请求的客户端变得更加容易。

是的,覆盖 POST 不太理想,但我认为 Google 约定 使用 X-HTTP-Method-Override 是一个合理/方便的解决方法。

如果轻松休息 可以使用 X-HTTP-Method-Override 标头调度 POST 请求 自动地,这将节省大量时间。我认为泽西岛刚刚添加了一些东西 像这样通过过滤方法,但我更愿意坚持使用 RESTeasy。

Are there any way that support the X-HTTP-Method-Override request header
(automatically/transparently) in RESTeasy?

This would
make it much easier to support clients that cannot send PUT/DELETE requests.

Yes, overriding POST is less than ideal but I think the Google convention of
using X-HTTP-Method-Override is a reasonable/convenient work-around.

If RESTeasy
could dispatch POST requests with the X-HTTP-Method-Override header
automatically it would be a big time saver. I think Jersey just added something
like this via a filtering approach, but I'd prefer to stick with RESTeasy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑凤梨 2025-01-08 06:11:35

最近我遇到了同样的问题,我找到的最佳解决方案是:

@Provider
@PreMatching
public class OverrideHttpMethodFilter implements ContainerRequestFilter {

@Override
public void filter(ContainerRequestContext requestContext)
        throws IOException {        
    String receivedMethod = requestContext.getMethod();
    String methodFromHeader = requestContext.getHeaderString("X-HTTP-Method-Override");
    if (methodFromHeader != null && !methodFromHeader.equals(receivedMethod)) {
        requestContext.setMethod(methodFromHeader);
    }
  }
}

Recently I had the same problem and the best solution I've found is:

@Provider
@PreMatching
public class OverrideHttpMethodFilter implements ContainerRequestFilter {

@Override
public void filter(ContainerRequestContext requestContext)
        throws IOException {        
    String receivedMethod = requestContext.getMethod();
    String methodFromHeader = requestContext.getHeaderString("X-HTTP-Method-Override");
    if (methodFromHeader != null && !methodFromHeader.equals(receivedMethod)) {
        requestContext.setMethod(methodFromHeader);
    }
  }
}
最偏执的依靠 2025-01-08 06:11:35

在 RESTeasy 中,通过使用拦截器来支持处理标头,这些拦截器在 参考指南

您想要的可能是一个 PreProcessInterceptor,它拦截调用、查找标头并根据需要更改方法字符串/重定向。

In RESTeasy processing headers are supported by using interceptors, which are described in the Reference Guide.

What you want, is probably a PreProcessInterceptor which intercepts the call, looks for the header and changes the method string/redirects as necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文