/**
  * Returns a new {@link EmbeddedChannel} that decodes the HTTP2 message content encoded in the
  * specified {@code contentEncoding}.
  *
  * @param contentEncoding the value of the {@code content-encoding} header
  * @return a new {@link ByteToMessageDecoder} if the specified encoding is supported. {@code null}
  *     otherwise (alternatively, you can throw a {@link Http2Exception} to block unknown
  *     encoding).
  * @throws Http2Exception If the specified encoding is not not supported and warrants an exception
  */
 protected EmbeddedChannel newContentDecoder(CharSequence contentEncoding) throws Http2Exception {
   if (GZIP.equalsIgnoreCase(contentEncoding) || XGZIP.equalsIgnoreCase(contentEncoding)) {
     return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
   }
   if (DEFLATE.equalsIgnoreCase(contentEncoding) || XDEFLATE.equalsIgnoreCase(contentEncoding)) {
     final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
     // To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
     return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));
   }
   // 'identity' or unsupported
   return null;
 }
Exemple #2
0
 public static InputStream decode(String codings, InputStream content)
     throws IOException, MessageFormatException {
   if (codings == null || codings.trim().equals("")) return content;
   String[] algos = codings.split("[ \t]*,[ \t]*");
   if (algos.length == 1 && IDENTITY.equalsIgnoreCase(algos[0])) return content;
   for (int i = 0; i < algos.length; i++) {
     if (CHUNKED.equalsIgnoreCase(algos[i])) {
       content = new ChunkedInputStream(content);
     } else if (DEFLATE.equalsIgnoreCase(algos[i])) {
       content = new DeflaterInputStream(content);
     } else if (GZIP.equalsIgnoreCase(algos[i])) {
       content = new GunzipInputStream(content);
     } else if (IDENTITY.equalsIgnoreCase(algos[i])) {
       // nothing to do
     } else throw new MessageFormatException("Unsupported coding : " + algos[i]);
   }
   return content;
 }