@@ -604,19 +604,18 @@ protected String getCookieNamePrefix(String name) {
604604 protected void copyResponseEntity (HttpResponse <InputStream > proxyResponse , HttpServletResponse servletResponse ,
605605 HttpRequest proxyRequest , HttpServletRequest servletRequest )
606606 throws IOException {
607- InputStream entity = proxyResponse .body ();
608- if (entity != null ) {
607+ InputStream inputStream = proxyResponse .body (); // will be closed by caller
608+ if (inputStream != null ) {
609609 // Check if chunked based on headers
610610 List <String > transferEncoding = proxyResponse .headers ().allValues ("Transfer-Encoding" );
611611 boolean isChunked = transferEncoding .stream ().anyMatch (te -> te .toLowerCase (Locale .ROOT ).contains ("chunked" ));
612612
613613 if (isChunked ) {
614614 // Flush intermediate results before blocking on input -- needed for SSE
615- InputStream is = entity ;
616615 OutputStream os = servletResponse .getOutputStream ();
617616 byte [] buffer = new byte [10 * 1024 ];
618617 int read ;
619- while ((read = is .read (buffer )) != -1 ) {
618+ while ((read = inputStream .read (buffer )) != -1 ) {
620619 os .write (buffer , 0 , read );
621620 /*-
622621 * if the stream from client is
@@ -631,14 +630,14 @@ protected void copyResponseEntity(HttpResponse<InputStream> proxyResponse, HttpS
631630 * To work around this, a flush is issued always if compression
632631 * is handled by the http client
633632 */
634- if (doHandleCompression || is .available () == 0 /* next is.read will block */ ) {
633+ if (doHandleCompression || inputStream .available () == 0 /* next is.read will block */ ) {
635634 os .flush ();
636635 }
637636 }
638637 // Entity closing/cleanup is done in the caller (#service)
639638 } else {
640639 OutputStream servletOutputStream = servletResponse .getOutputStream ();
641- entity .transferTo (servletOutputStream );
640+ inputStream .transferTo (servletOutputStream );
642641 }
643642 }
644643 }
0 commit comments