gnodet-bot commented on code in PR #27755:
URL: https://github.com/apache/camel/pull/27755#discussion_r4253471141


##########
components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpConverter.java:
##########
@@ -84,16 +86,23 @@ public static InputStream toInputStream(HttpServletRequest 
request, Exchange exc
             return null;
         }
         InputStream is = request.getInputStream();
-        if (is != null && is.available() <= 0) {
-            // there is no data, so we cannot uncompress etc.
+        if (is == null) {
+            return null;
+        }
+        boolean skip = exchange != null && 
exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class);
+        if (skip || 
!GZIPHelper.isGzip(request.getHeader(Exchange.CONTENT_ENCODING))) {
             return is;
         }
-        if (exchange == null || 
!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, 
Boolean.class)) {
-            String contentEncoding = 
request.getHeader(Exchange.CONTENT_ENCODING);
-            return GZIPHelper.uncompressGzip(contentEncoding, is);
-        } else {
+        // an empty body cannot be uncompressed. Whether the body is empty is 
only known after reading:
+        // available() is 0 as long as no data has arrived, such as when the 
client waits for 100 Continue
+        // or sends the body later than the headers
+        PushbackInputStream pushback = new PushbackInputStream(is, 1);
+        int first = pushback.read();
+        if (first == -1) {
             return is;

Review Comment:
   After `pushback.read()` returns -1, this path returns the raw `is` while the 
`PushbackInputStream` wrapper that already consumed EOF from it is silently 
abandoned.
   
   While functionally harmless in most servlet containers (the body is empty, 
so `is` is exhausted anyway), returning `pushback` here is the more hygienic 
choice: it keeps the read position consistent and avoids surprising behaviour 
if the container tracks wrapper state.
   
   ```suggestion
               return pushback;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to