Ejemplo n.º 1
0
 public static boolean expectContent(RequestHeader request) throws MessageFormatException {
   String method = request.getMethod();
   if (!"POST".equalsIgnoreCase(method) && !"PUT".equalsIgnoreCase(method)) return false;
   String contentLength = request.getHeader(CONTENT_LENGTH);
   String transferEncoding = request.getHeader(TRANSFER_ENCODING);
   if (transferEncoding != null) return true;
   if (contentLength == null)
     throw new MessageFormatException(
         "Request content expected, but no length specified!", request.getHeader());
   try {
     int cl = Integer.parseInt(contentLength);
     if (cl < 0)
       throw new MessageFormatException(
           "Negative content length: " + contentLength, request.getHeader());
     if (cl == 0) return false;
     return true;
   } catch (NumberFormatException nfe) {
     throw new MessageFormatException(
         "Invalid content length: " + contentLength, nfe, request.getHeader());
   }
 }
Ejemplo n.º 2
0
 public static boolean isExpectContinue(RequestHeader request) throws MessageFormatException {
   return "100-continue".equalsIgnoreCase(request.getHeader("Expect"));
 }
Ejemplo n.º 3
0
 public static boolean expectContent(RequestHeader request, ResponseHeader response)
     throws MessageFormatException {
   String method = request.getMethod();
   String status = response.getStatus();
   return !("HEAD".equalsIgnoreCase(method) || "204".equals(status) || "304".equals(status));
 }