Hi,
I have been seeing extra 400 errors coming from NGINX when using Clojure. I put together a simple Java rewrite handler as follows:
@Override
public Object[] invoke(Map<String, Object> request) {
NginxJavaRequest nginxJavaRequest = (NginxJavaRequest) request;
String uri = nginxJavaRequest.getVariable("request_uri");
if (uri.endsWith("error")) {
return new Object[]{401, ArrayMap.create("www-authenticate", "Basic realm=\"Secure Area\""),
"<HTML><BODY><H1>401 Unauthorized.</H1></BODY></HTML>"};
} else {
return PHASE_DONE;
}
}
If I hit the "error" endpoint with a POST or PUT, then I will get both an HTTP 401 and an HTTP 400.
I believe what is happening is that the header of the request is being passed to the rewrite handler and this causes the 401 as expected. However, the body of the request is not consumed. NGINX then sees the body as a new request. Obviously the body is not formatted as a proper request, so a 400 is generated. This may only be an issue if keepalive connections are being used.
Is there a way to cause the body to be discarded in the event of an error so that it doesn't produce a spurious 400? The only way I have found is to set "always_read_body on;". However, this has a performance overhead that we would like to avoid.
Thanks,
Seth