private int getEntityLength() throws IOException {
    // Default to -1, which will be treated as an unknown entity length leading to the usage of
    // chunked encoding.
    int entityLength = -1;
    switch (chunkedEncoding.toLowerCase()) {
      case "true":
      case "1":
        break;
      case "auto":
        if (StringUtilities.nullSafeEqualsIgnoreCase(
            sourceRequest.getHeader("transfer-encoding"), "chunked")) {
          break;
        }
      case "false":
      case "0":
        // todo: optimize so subsequent calls to this method do not need to read/copy the entity
        final ByteArrayOutputStream sourceEntity = new ByteArrayOutputStream();
        RawInputStreamReader.instance().copyTo(sourceRequest.getInputStream(), sourceEntity);

        final ServletInputStream readableEntity =
            new BufferedServletInputStream(new ByteArrayInputStream(sourceEntity.toByteArray()));
        sourceRequest = new HttpServletRequestWrapper(sourceRequest, readableEntity);

        entityLength = sourceEntity.size();
        break;
      default:
        LOG.warn("Invalid chunked encoding value -- using chunked encoding");
        break;
    }
    return entityLength;
  }
  @Override
  public void applyTo(MutableHttpServletResponse response) throws IOException {
    if (responseHeaderManager().hasHeaders()) {
      responseHeaderManager().applyTo(response);
    }

    if (HttpStatusCode.UNSUPPORTED_RESPONSE_CODE.intValue() != status
        && delegatedAction != FilterAction.NOT_SET) {
      response.setStatus(status);
    }

    if (directorOutputStream.size() > 0) {
      response.setContentLength(directorOutputStream.size());
      response.setHeader("Content-Length", String.valueOf(directorOutputStream.size()));
      RawInputStreamReader.instance()
          .copyTo(
              new ByteArrayInputStream(getResponseMessageBodyBytes()), response.getOutputStream());
    }
  }