Skip to content

Commit c2d948a

Browse files
authored
fix(sigv4): Convert empty query parameters to null (#6082)
1 parent 86d3ad5 commit c2d948a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/aws_signature_v4/lib/src/signer/aws_signer.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ class AWSSigV4Signer {
256256
}) {
257257
// The signing process requires component keys be encoded. However, the
258258
// actual HTTP request should have the pre-encoded keys.
259-
final queryParameters = Map.of(canonicalRequest.queryParameters);
259+
Map<String, String>? queryParameters =
260+
Map.of(canonicalRequest.queryParameters);
260261

261262
// Similar to query parameters, some header values are canonicalized for
262263
// signing. However their original values should be included in the
@@ -284,6 +285,13 @@ class AWSSigV4Signer {
284285
}
285286
}
286287

288+
// Web sends an OPTIONS request to verify CORS compatibility with the URL.
289+
// A 404 can be returned if the URL contains unexpected query Parameters
290+
// and URI.toString() appends a "?" to the URL for an empty query parameter
291+
// map. Set the query parameter to null if it empty to avoid this.
292+
// https://github.com/dart-lang/sdk/issues/51656
293+
queryParameters = queryParameters.isEmpty ? null : queryParameters;
294+
287295
// On Web, sign the `Host` and `Content-Length` headers, but do not send
288296
// them as part of the request, since these will be included automatically
289297
// by the browser and most now restrict the ability to set them via code.

0 commit comments

Comments
 (0)