需要用 header 的操作拦截来自客户端的 PUT 调用

Need to intercept the PUT calls from client with the header of manipulation

我写了一个 jetty http 代理服务器,因为我需要使用 header 操作拦截来自客户端的 PUT 调用。

当我提到 jetty 时,jetty 中有一些修复程序来处理问题(100-continue)header,所以我认为中断和操作请求对我的请求很有用。谁能建议如何在我的 java 代码中实现这个逻辑。

这可以通过过滤器接口实现,您需要按照以下代码示例在 doFilter 方法中实现该接口并执行您的逻辑。

public class HttpFilter implements Filter
{
  public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain filterChain) throws IOException, ServletException
   {
       HttpServletRequest httpRequest = (HttpServletRequest) request;        
       if(httpRequest.getMethod().equalsIgnoreCase("PUT")){

       }
       filterChain.doFilter(request, response);
   }
    // other methods etc
}

然后您需要确保在 web.xml

中声明您的过滤器和过滤器映射条目