@@ -88,7 +88,7 @@ public void handle(final HttpExchange exchange) throws IOException {
88
88
}
89
89
try {
90
90
// 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 () ));
92
92
if (Regex .simpleMatch ("GET /storage/v1/b/" + bucket + "/o*" , request )) {
93
93
// List Objects https://cloud.google.com/storage/docs/json_api/v1/objects/list
94
94
final Map <String , String > params = new HashMap <>();
@@ -155,7 +155,7 @@ public void handle(final HttpExchange exchange) throws IOException {
155
155
// Batch https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch
156
156
final String uri = "/storage/v1/b/" + bucket + "/o/" ;
157
157
final StringBuilder batch = new StringBuilder ();
158
- for (String line : Streams .readAllLines (wrappedRequest )) {
158
+ for (String line : Streams .readAllLines (requestBody . streamInput () )) {
159
159
if (line .length () == 0 || line .startsWith ("--" ) || line .toLowerCase (Locale .ROOT ).startsWith ("content" )) {
160
160
batch .append (line ).append ('\n' );
161
161
} else if (line .startsWith ("DELETE" )) {
@@ -174,7 +174,7 @@ public void handle(final HttpExchange exchange) throws IOException {
174
174
175
175
} else if (Regex .simpleMatch ("POST /upload/storage/v1/b/" + bucket + "/*uploadType=multipart*" , request )) {
176
176
// Multipart upload
177
- Optional <Tuple <String , BytesReference >> content = parseMultipartRequestBody (wrappedRequest );
177
+ Optional <Tuple <String , BytesReference >> content = parseMultipartRequestBody (requestBody . streamInput () );
178
178
if (content .isPresent ()) {
179
179
blobs .put (content .get ().v1 (), content .get ().v2 ());
180
180
@@ -194,7 +194,7 @@ public void handle(final HttpExchange exchange) throws IOException {
194
194
final String blobName = params .get ("name" );
195
195
blobs .put (blobName , BytesArray .EMPTY );
196
196
197
- byte [] response = Streams . readFully ( wrappedRequest ) .utf8ToString ().getBytes (UTF_8 );
197
+ byte [] response = requestBody .utf8ToString ().getBytes (UTF_8 );
198
198
exchange .getResponseHeaders ().add ("Content-Type" , "application/json" );
199
199
exchange .getResponseHeaders ().add ("Location" , httpServerUrl (exchange ) + "/upload/storage/v1/b/" + bucket + "/o?"
200
200
+ "uploadType=resumable"
@@ -219,7 +219,7 @@ public void handle(final HttpExchange exchange) throws IOException {
219
219
final int start = getContentRangeStart (range );
220
220
final int end = getContentRangeEnd (range );
221
221
222
- blob = new CompositeBytesReference (blob , Streams . readFully ( wrappedRequest ) );
222
+ blob = new CompositeBytesReference (blob , requestBody );
223
223
blobs .put (blobName , blob );
224
224
225
225
if (limit == null ) {
0 commit comments