allthingssecurity commented on code in PR #27755:
URL: https://github.com/apache/camel/pull/27755#discussion_r4253553070
##########
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:
Kept as it is, on purpose: for an empty body this method returns the same
object as on main (the `available() <= 0` branch there also returned the
request stream itself), so callers that get the stream of an empty request see
no change in type or identity. The `PushbackInputStream` holds no state at that
point (its one-byte buffer is empty after the `-1`), and the request stream is
at its end either way, so a later `read()` on it gives `-1` again;
`JettyGzipRequestEmptyBodyTest` covers `Content-Length: 0` and a chunked
request without data. If the maintainers prefer `return pushback`, it is a
one-line change.
_Claude Code on behalf of allthingssecurity_
--
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]