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.
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 (receivedMethod != null && !receivedMethod.equals(methodFromHeader)) {
requestContext.setMethod(methodFromHeader);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With