@@ -61,6 +61,9 @@ public OutputStream wrap(OutputStream out, boolean isChecksumValidationEnabled)
6161 * @throws IOException if the checksums do not match.
6262 */
6363 public void validate (HttpResponse response , byte [] content ) throws IOException {
64+ if (isTranscoded (response )) {
65+ return ;
66+ }
6467 Map <String , String > hashes = ChecksumResponseParser .extractHashesFromHeader (response );
6568 String expectedCrc32cBase64 = hashes .get ("crc32c" );
6669 if (expectedCrc32cBase64 != null ) {
@@ -76,6 +79,9 @@ public void validate(HttpResponse response, byte[] content) throws IOException {
7679 */
7780 @ SuppressWarnings ("UnstableApiUsage" )
7881 public void validate (HttpResponse response , OutputStream activeStream ) throws IOException {
82+ if (isTranscoded (response )) {
83+ return ;
84+ }
7985 if (activeStream instanceof HashingOutputStream ) {
8086 HashingOutputStream targetStream = (HashingOutputStream ) activeStream ;
8187
@@ -87,6 +93,24 @@ public void validate(HttpResponse response, OutputStream activeStream) throws IO
8793 }
8894 }
8995
96+ private boolean isTranscoded (HttpResponse response ) {
97+ com .google .api .client .http .HttpHeaders headers = response .getHeaders ();
98+ String storedEncoding =
99+ HttpClientContext .firstHeaderValue (headers , "x-goog-stored-content-encoding" );
100+ String storedLength =
101+ HttpClientContext .firstHeaderValue (headers , "x-goog-stored-content-length" );
102+ return storedEncoding != null || storedLength != null || isDecompressedByClient (response );
103+ }
104+
105+ private boolean isDecompressedByClient (HttpResponse response ) {
106+ boolean returnRaw = response .getRequest ().getResponseReturnRawInputStream ();
107+ if (!returnRaw ) {
108+ String encoding = response .getHeaders ().getContentEncoding ();
109+ return encoding != null && encoding .contains ("gzip" );
110+ }
111+ return false ;
112+ }
113+
90114 /**
91115 * Validates a calculated CRC32C value against GCS's expected base64-encoded value.
92116 *
0 commit comments