Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/aws-s3: resolve all headers on response #5195

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions packages/@uppy/aws-s3-multipart/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('AwsS3Multipart', () => {
expect(uploadSuccessHandler.mock.calls[0][1]).toStrictEqual({
body: {
ETag: 'test',
etag: 'test',
location: 'http://example.com',
},
status: 200,
Expand Down Expand Up @@ -257,16 +258,16 @@ describe('AwsS3Multipart', () => {
.mock.calls[0][1]

expect(completeCall.parts).toEqual([
{ ETag: 'test', PartNumber: 1 },
{ ETag: 'test', PartNumber: 2 },
{ ETag: 'test', PartNumber: 3 },
{ ETag: 'test', PartNumber: 4 },
{ ETag: 'test', PartNumber: 5 },
{ ETag: 'test', PartNumber: 6 },
{ ETag: 'test', PartNumber: 7 },
{ ETag: 'test', PartNumber: 8 },
{ ETag: 'test', PartNumber: 9 },
{ ETag: 'test', PartNumber: 10 },
{ ETag: 'test', etag: 'test', PartNumber: 1 },
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
{ ETag: 'test', etag: 'test', PartNumber: 2 },
{ ETag: 'test', etag: 'test', PartNumber: 3 },
{ ETag: 'test', etag: 'test', PartNumber: 4 },
{ ETag: 'test', etag: 'test', PartNumber: 5 },
{ ETag: 'test', etag: 'test', PartNumber: 6 },
{ ETag: 'test', etag: 'test', PartNumber: 7 },
{ ETag: 'test', etag: 'test', PartNumber: 8 },
{ ETag: 'test', etag: 'test', PartNumber: 9 },
{ ETag: 'test', etag: 'test', PartNumber: 10 },
])
})

Expand Down
19 changes: 16 additions & 3 deletions packages/@uppy/aws-s3-multipart/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@
;(error as any).source = { status: 403 }
reject(error)
})
xhr.addEventListener('load', (ev) => {
xhr.addEventListener('load', () => {
cleanup()

if (
Expand All @@ -752,6 +752,19 @@
const etag = xhr.getResponseHeader('ETag')
const location = xhr.getResponseHeader('Location')
Murderlon marked this conversation as resolved.
Show resolved Hide resolved

// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#examples
const arr = xhr
.getAllResponseHeaders()
.trim()
.split(/[\r\n]+/)
const headersMap: Record<string, string> = { __proto__: null }

Check failure on line 760 in packages/@uppy/aws-s3-multipart/src/index.ts

View workflow job for this annotation

GitHub Actions / Type tests

Type 'null' is not assignable to type 'string'.

Check failure on line 760 in packages/@uppy/aws-s3-multipart/src/index.ts

View workflow job for this annotation

GitHub Actions / Type tests

Type 'null' is not assignable to type 'string'.
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
for (const line of arr) {
const parts = line.split(': ')
const header = parts.shift()!
const value = parts.join(': ')
headersMap[header] = value
}

if (method.toUpperCase() === 'POST' && location === null) {
// Not being able to read the Location header is not a fatal error.
// eslint-disable-next-line no-console
Expand All @@ -770,8 +783,8 @@

onComplete?.(etag)
resolve({
ETag: etag,
...(location ? { location } : undefined),
...headersMap,
ETag: etag, // keep capitalised ETag for backwards compatiblity
})
})

Expand Down
Loading