@@ -88,7 +88,7 @@ public void handle(final HttpExchange exchange) throws IOException {
8888 }
8989 try {
9090 // Request body is closed in the finally block
91- final InputStream wrappedRequest = Streams .noCloseStream (exchange .getRequestBody ());
91+ final BytesReference requestBody = Streams .readFully ( Streams . noCloseStream (exchange .getRequestBody () ));
9292 if (Regex .simpleMatch ("GET /storage/v1/b/" + bucket + "/o*" , request )) {
9393 // List Objects https://cloud.google.com/storage/docs/json_api/v1/objects/list
9494 final Map <String , String > params = new HashMap <>();
@@ -155,7 +155,7 @@ public void handle(final HttpExchange exchange) throws IOException {
155155 // Batch https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch
156156 final String uri = "/storage/v1/b/" + bucket + "/o/" ;
157157 final StringBuilder batch = new StringBuilder ();
158- for (String line : Streams .readAllLines (wrappedRequest )) {
158+ for (String line : Streams .readAllLines (requestBody . streamInput () )) {
159159 if (line .length () == 0 || line .startsWith ("--" ) || line .toLowerCase (Locale .ROOT ).startsWith ("content" )) {
160160 batch .append (line ).append ('\n' );
161161 } else if (line .startsWith ("DELETE" )) {
@@ -174,7 +174,7 @@ public void handle(final HttpExchange exchange) throws IOException {
174174
175175 } else if (Regex .simpleMatch ("POST /upload/storage/v1/b/" + bucket + "/*uploadType=multipart*" , request )) {
176176 // Multipart upload
177- Optional <Tuple <String , BytesReference >> content = parseMultipartRequestBody (wrappedRequest );
177+ Optional <Tuple <String , BytesReference >> content = parseMultipartRequestBody (requestBody . streamInput () );
178178 if (content .isPresent ()) {
179179 blobs .put (content .get ().v1 (), content .get ().v2 ());
180180
@@ -194,7 +194,7 @@ public void handle(final HttpExchange exchange) throws IOException {
194194 final String blobName = params .get ("name" );
195195 blobs .put (blobName , BytesArray .EMPTY );
196196
197- byte [] response = Streams . readFully ( wrappedRequest ) .utf8ToString ().getBytes (UTF_8 );
197+ byte [] response = requestBody .utf8ToString ().getBytes (UTF_8 );
198198 exchange .getResponseHeaders ().add ("Content-Type" , "application/json" );
199199 exchange .getResponseHeaders ().add ("Location" , httpServerUrl (exchange ) + "/upload/storage/v1/b/" + bucket + "/o?"
200200 + "uploadType=resumable"
@@ -219,7 +219,7 @@ public void handle(final HttpExchange exchange) throws IOException {
219219 final int start = getContentRangeStart (range );
220220 final int end = getContentRangeEnd (range );
221221
222- blob = new CompositeBytesReference (blob , Streams . readFully ( wrappedRequest ) );
222+ blob = new CompositeBytesReference (blob , requestBody );
223223 blobs .put (blobName , blob );
224224
225225 if (limit == null ) {
0 commit comments