Skip to content

Commit 0e083e4

Browse files
patrickhoettePatrick Hoette
andauthored
[aws-api] Fix DELETE calls not working with v4 signer (#1037)
OkHttp3 sets the body of a DELETE call to a byte array of length 0. The v4 signer interceptor only checks if the body is null and if its not it sets the content type to application/json. This causes an invalid REST request to be created. Fixed by expanding the check to also make sure the body has a content length greater than 0. Github Issue: #1028 Co-authored-by: Patrick Hoette <[email protected]>
1 parent cdc872a commit 0e083e4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

aws-api/src/main/java/com/amplifyframework/api/aws/sigv4/AppSyncSigV4SignerInterceptor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,12 @@ public Response intercept(Chain chain) throws IOException {
227227

228228
//Set the URL and Method
229229
okReqBuilder.url(req.url());
230-
final RequestBody requestBody = req.body() != null ?
231-
RequestBody.create(bodyBytes, JSON_MEDIA_TYPE) : null;
230+
final RequestBody requestBody;
231+
if (req.body() != null && req.body().contentLength() > 0) {
232+
requestBody = RequestBody.create(bodyBytes, JSON_MEDIA_TYPE);
233+
} else {
234+
requestBody = null;
235+
}
232236

233237
okReqBuilder.method(req.method(), requestBody);
234238

0 commit comments

Comments
 (0)