-
Notifications
You must be signed in to change notification settings - Fork 472
Add Brotli(br) content decoding support #2572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |||||||||||||||||||||||||||||||||
| import org.apache.axis2.transport.http.*; | ||||||||||||||||||||||||||||||||||
| import org.apache.axis2.util.JavaUtils; | ||||||||||||||||||||||||||||||||||
| import org.apache.axis2.util.MessageProcessorSelector; | ||||||||||||||||||||||||||||||||||
| import org.apache.commons.compress.compressors.brotli.BrotliCompressorInputStream; | ||||||||||||||||||||||||||||||||||
| import org.apache.commons.logging.Log; | ||||||||||||||||||||||||||||||||||
| import org.apache.commons.logging.LogFactory; | ||||||||||||||||||||||||||||||||||
| import org.apache.http.protocol.HTTP; | ||||||||||||||||||||||||||||||||||
|
|
@@ -39,6 +40,7 @@ | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||
| import java.io.InputStream; | ||||||||||||||||||||||||||||||||||
| import java.io.PushbackInputStream; | ||||||||||||||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||||||||||||||
| import java.util.Iterator; | ||||||||||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||||||||||
|
|
@@ -102,7 +104,7 @@ public OMElement getDocument(MessageContext msgCtx, InputStream in) throws | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| String contentType = (String) msgCtx.getProperty(Constants.Configuration.CONTENT_TYPE); | ||||||||||||||||||||||||||||||||||
| String _contentType = getContentType(contentType, msgCtx); | ||||||||||||||||||||||||||||||||||
| in = HTTPTransportUtils.handleGZip(msgCtx, in); | ||||||||||||||||||||||||||||||||||
| in = handleContentEncoding(msgCtx, in); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| AxisConfiguration configuration = msgCtx.getConfigurationContext().getAxisConfiguration(); | ||||||||||||||||||||||||||||||||||
| Parameter useFallbackParameter = | ||||||||||||||||||||||||||||||||||
|
|
@@ -306,4 +308,22 @@ public static String getContentType(String contentType, MessageContext msgContex | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return type; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private static InputStream handleContentEncoding(MessageContext msgContext, InputStream in) throws IOException { | ||||||||||||||||||||||||||||||||||
| if (checkContentEncodingMatches(msgContext, "br")) { | ||||||||||||||||||||||||||||||||||
| PushbackInputStream pushbackInputStream = new PushbackInputStream(in); | ||||||||||||||||||||||||||||||||||
| int bytesRead = pushbackInputStream.read(); | ||||||||||||||||||||||||||||||||||
| if (bytesRead != -1) { | ||||||||||||||||||||||||||||||||||
| pushbackInputStream.unread(bytesRead); | ||||||||||||||||||||||||||||||||||
| return new BrotliCompressorInputStream(pushbackInputStream); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return HTTPTransportUtils.handleGZip(msgContext, in); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private static boolean checkContentEncodingMatches(MessageContext msgContext, String encoding) { | ||||||||||||||||||||||||||||||||||
| Map headers = (Map)msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); | ||||||||||||||||||||||||||||||||||
| return headers != null && (encoding.equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING)) | ||||||||||||||||||||||||||||||||||
| || encoding.equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING_LOWERCASE))); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+324
to
+328
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Match the Content-Encoding value case-insensitively.
♻️ Proposed adjustment private static boolean checkContentEncodingMatches(MessageContext msgContext, String encoding) {
Map headers = (Map)msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
- return headers != null && (encoding.equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING))
- || encoding.equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING_LOWERCASE)));
+ if (headers == null) {
+ return false;
+ }
+ Object value = headers.get(HTTPConstants.HEADER_CONTENT_ENCODING);
+ if (value == null) {
+ value = headers.get(HTTPConstants.HEADER_CONTENT_ENCODING_LOWERCASE);
+ }
+ return value instanceof String && encoding.equalsIgnoreCase(((String) value).trim());
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a behavioural change and may break existing flows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Per RFC 7231 §3.1.2.2, content-coding token comparisons are specified as case-insensitive, so the current case-sensitive behavior is technically a spec deviation rather than an intentional design choice. That said, if you'd prefer to keep the scope of this PR minimal and address case normalization separately, that's also a reasonable call. |
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.