I want to check the request header whether it contains a specific header or not before continuing with the body. For example, I want to check if multipart / form-data contains "Authorization" in the header or not. If this is not the case, there is no need to continue loading the multi-page body, which is usually large enough to download files.
Does the servlet allow this? I tried to do a Google search by accident, but there is no luck. Here is the code I'm trying to execute on my servlet, but it still continues with getting the body until this doPost called. It seems that the stream is fully received before the servlet is called.
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setContentType("text/plain"); if (request.getHeader("Authorization") == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); out.println("Status: " + HttpServletResponse.SC_UNAUTHORIZED + " - UNAUTHORIZED"); return; }
source share