@@ -104,6 +104,20 @@ class S3ServiceConfiguration extends BaseServiceConfiguration {
104
104
return decodedLength + metadataLength;
105
105
}
106
106
107
+ /// Whether [request] should be chunked, given the environment and whether
108
+ /// chunking was requested.
109
+ bool _shouldChunk (AWSBaseHttpRequest request) {
110
+ var isChunkableMethod = true ;
111
+ if (zIsWeb) {
112
+ // Browser APIs (XMLHttpRequest, fetch) disallow sending bodies for these
113
+ // methods and, thus, chunked requests are not possible and we should not
114
+ // try.
115
+ isChunkableMethod = request.method != AWSHttpMethod .get &&
116
+ request.method != AWSHttpMethod .head;
117
+ }
118
+ return chunked && isChunkableMethod;
119
+ }
120
+
107
121
@override
108
122
void applySigned (
109
123
Map <String , String > headers, {
@@ -122,7 +136,7 @@ class S3ServiceConfiguration extends BaseServiceConfiguration {
122
136
contentLength: contentLength,
123
137
);
124
138
125
- if (chunked ) {
139
+ if (_shouldChunk (request) ) {
126
140
// Raw size of the data to be sent, before compression and without metadata.
127
141
headers[AWSHeaders .decodedContentLength] = contentLength.toString ();
128
142
@@ -148,7 +162,7 @@ class S3ServiceConfiguration extends BaseServiceConfiguration {
148
162
required bool presignedUrl,
149
163
}) async {
150
164
// Only unchunked, signed requests are hashed as other services would be.
151
- if (signPayload && ! chunked ) {
165
+ if (signPayload && ! _shouldChunk (request) ) {
152
166
return super .hashPayload (request, presignedUrl: presignedUrl);
153
167
}
154
168
return hashPayloadSync (request, presignedUrl: presignedUrl);
@@ -162,7 +176,7 @@ class S3ServiceConfiguration extends BaseServiceConfiguration {
162
176
if (presignedUrl || ! signPayload) {
163
177
return unsignedPayloadHash;
164
178
}
165
- if (chunked ) {
179
+ if (_shouldChunk (request) ) {
166
180
return chunkedPayloadSeedHash;
167
181
}
168
182
return super .hashPayloadSync (request, presignedUrl: presignedUrl);
@@ -177,7 +191,9 @@ class S3ServiceConfiguration extends BaseServiceConfiguration {
177
191
required AWSCredentialScope credentialScope,
178
192
required CanonicalRequest canonicalRequest,
179
193
}) async * {
180
- if (canonicalRequest.presignedUrl || ! signPayload || ! chunked) {
194
+ if (canonicalRequest.presignedUrl ||
195
+ ! signPayload ||
196
+ ! _shouldChunk (canonicalRequest.request)) {
181
197
yield * super .signBody (
182
198
algorithm: algorithm,
183
199
contentLength: contentLength,
0 commit comments