Skip to content

Commit

Permalink
fix for bug: #3640
Browse files Browse the repository at this point in the history
Signed-off-by: Jitendra Kumar <jkjitend@amazon.com>
  • Loading branch information
kumjiten committed Jun 23, 2022
1 parent 45ec5ed commit d023308
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
23 changes: 8 additions & 15 deletions client/rest/src/main/java/org/opensearch/client/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ public InputStream getContent() throws IOException {
}

/**
* A gzip compressing enrity doesn't worked with chunked encoding with sigv4
* A gzip compressing entity doesn't work with chunked encoding with sigv4
*
* @return false
*/
Expand All @@ -966,25 +966,18 @@ public boolean isChunked() {
}

/**
* A gzip entity require to content length in http headers
* A gzip entity requires content length in http headers
* as it doesn't work with chunked encoding for sigv4
*
* @return content lenght of gzip entity
* @return content length of gzip entity
*/
@Override
public long getContentLength() {
long size = 0;
int chunk = 0;
byte[] buffer = new byte[1024];

try {
InputStream is = getContent();

while ((chunk = is.read(buffer)) != -1) {
size += chunk;
}
} catch (Exception ex) {
throw new RuntimeException("failed to get compressed content lenght: " + ex.getMessage());
long size;
try (InputStream is = getContent()) {
size = is.readAllBytes().length;
} catch (IOException ex) {
size = -1L;
}

return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
Expand Down

0 comments on commit d023308

Please sign in to comment.