@Override
    public ServletInputStream getInputStream() throws IOException {
        HttpServletRequest request = (HttpServletRequest) super.getRequest();

        // disable stream cache for chunked transfer encoding
        String transferEncoding = request.getHeader("Transfer-Encoding");
        if ("chunked".equals(transferEncoding)) {
            return super.getInputStream();
        }

        // disable stream cache for multipart/form-data file upload
        // -> upload might be very large and might lead to out-of-memory error if we try to cache the bytes
        String contentType = request.getHeader("Content-Type");
        if (contentType != null && contentType.startsWith("multipart/form-data")) {
            return super.getInputStream();
        }

        if (cachedBytes == null) {
            cacheInputStream();
        }
        return new CachedServletInputStream();
    }
Http request wrapper. Wraps the request so 'getInputStream()' can be called multiple times.
Also has methods for checking if request has been consumed.
src/main/java/spark/embeddedserver/jetty/HttpRequestWrapper.java