Skip to content

Commit 165197e

Browse files
authored
fix: use correct format for last modified date header (#192)
1 parent 05692cb commit 165197e

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

src/routes/object/getObject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async function requestHandler(
9292
.header('Cache-Control', data.metadata.cacheControl)
9393
.header('ETag', data.metadata.eTag)
9494
.header('Content-Length', data.metadata.contentLength)
95-
.header('Last-Modified', data.metadata.lastModified)
95+
.header('Last-Modified', data.metadata.lastModified?.toUTCString())
9696
if (data.metadata.contentRange) {
9797
response.header('Content-Range', data.metadata.contentRange)
9898
}

src/routes/object/getPublicObject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default async function routes(fastify: FastifyInstance) {
8787
.header('Cache-Control', data.metadata.cacheControl)
8888
.header('Content-Length', data.metadata.contentLength)
8989
.header('ETag', data.metadata.eTag)
90-
.header('Last-Modified', data.metadata.lastModified)
90+
.header('Last-Modified', data.metadata.lastModified?.toUTCString())
9191
if (data.metadata.contentRange) {
9292
response.header('Content-Range', data.metadata.contentRange)
9393
}

src/routes/object/getSignedObject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default async function routes(fastify: FastifyInstance) {
8787
.header('Cache-Control', data.metadata.cacheControl)
8888
.header('Content-Length', data.metadata.contentLength)
8989
.header('ETag', data.metadata.eTag)
90-
.header('Last-Modified', data.metadata.lastModified)
90+
.header('Last-Modified', data.metadata.lastModified?.toUTCString())
9191
if (data.metadata.contentRange) {
9292
response.header('Content-Range', data.metadata.contentRange)
9393
}

src/test/bucket.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ beforeAll(() => {
1818
httpStatusCode: 200,
1919
size: 3746,
2020
mimetype: 'image/png',
21+
lastModified: new Date('Thu, 12 Aug 2021 16:00:00 GMT'),
22+
eTag: 'abc',
2123
},
2224
body: Buffer.from(''),
2325
})
@@ -202,6 +204,8 @@ describe('testing public bucket functionality', () => {
202204
url: `/object/public/public-bucket/favicon.ico`,
203205
})
204206
expect(publicResponse.statusCode).toBe(200)
207+
expect(publicResponse.headers['etag']).toBe('abc')
208+
expect(publicResponse.headers['last-modified']).toBe('Thu, 12 Aug 2021 16:00:00 GMT')
205209

206210
const mockGetObject = jest.spyOn(S3Backend.prototype, 'getObject')
207211
mockGetObject.mockRejectedValue({
@@ -213,13 +217,13 @@ describe('testing public bucket functionality', () => {
213217
method: 'GET',
214218
url: `/object/public/public-bucket/favicon.ico`,
215219
headers: {
216-
'if-modified-since': 'Fri Aug 13 2021 00:00:00 GMT+0800 (Singapore Standard Time)',
220+
'if-modified-since': 'Thu, 12 Aug 2021 16:00:00 GMT',
217221
'if-none-match': 'abc',
218222
},
219223
})
220224
expect(notModifiedResponse.statusCode).toBe(304)
221225
expect(mockGetObject.mock.calls[1][2]).toMatchObject({
222-
ifModifiedSince: 'Fri Aug 13 2021 00:00:00 GMT+0800 (Singapore Standard Time)',
226+
ifModifiedSince: 'Thu, 12 Aug 2021 16:00:00 GMT',
223227
ifNoneMatch: 'abc',
224228
})
225229

src/test/object.test.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ beforeEach(() => {
3232
httpStatusCode: 200,
3333
size: 3746,
3434
mimetype: 'image/png',
35+
lastModified: new Date('Thu, 12 Aug 2021 16:00:00 GMT'),
36+
eTag: 'abc',
3537
},
3638
body: Buffer.from(''),
3739
})
@@ -76,6 +78,8 @@ describe('testing GET object', () => {
7678
},
7779
})
7880
expect(response.statusCode).toBe(200)
81+
expect(response.headers['etag']).toBe('abc')
82+
expect(response.headers['last-modified']).toBe('Thu, 12 Aug 2021 16:00:00 GMT')
7983
expect(S3Backend.prototype.getObject).toBeCalled()
8084
})
8185

@@ -91,13 +95,13 @@ describe('testing GET object', () => {
9195
url: '/object/authenticated/bucket2/authenticated/casestudy.png',
9296
headers: {
9397
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
94-
'if-modified-since': 'Fri Aug 13 2021 00:00:00 GMT+0800 (Singapore Standard Time)',
98+
'if-modified-since': 'Thu, 12 Aug 2021 16:00:00 GMT',
9599
'if-none-match': 'abc',
96100
},
97101
})
98102
expect(response.statusCode).toBe(304)
99103
expect(mockGetObject.mock.calls[0][2]).toMatchObject({
100-
ifModifiedSince: 'Fri Aug 13 2021 00:00:00 GMT+0800 (Singapore Standard Time)',
104+
ifModifiedSince: 'Thu, 12 Aug 2021 16:00:00 GMT',
101105
ifNoneMatch: 'abc',
102106
})
103107
})
@@ -1246,6 +1250,8 @@ describe('testing retrieving signed URL', () => {
12461250
url: `/object/sign/${urlToSign}?token=${jwtToken}`,
12471251
})
12481252
expect(response.statusCode).toBe(200)
1253+
expect(response.headers['etag']).toBe('abc')
1254+
expect(response.headers['last-modified']).toBe('Thu, 12 Aug 2021 16:00:00 GMT')
12491255
})
12501256

12511257
test('forward 304 and If-Modified-Since/If-None-Match headers', async () => {
@@ -1261,13 +1267,13 @@ describe('testing retrieving signed URL', () => {
12611267
method: 'GET',
12621268
url: `/object/sign/${urlToSign}?token=${jwtToken}`,
12631269
headers: {
1264-
'if-modified-since': 'Fri Aug 13 2021 00:00:00 GMT+0800 (Singapore Standard Time)',
1270+
'if-modified-since': 'Thu, 12 Aug 2021 16:00:00 GMT',
12651271
'if-none-match': 'abc',
12661272
},
12671273
})
12681274
expect(response.statusCode).toBe(304)
12691275
expect(mockGetObject.mock.calls[0][2]).toMatchObject({
1270-
ifModifiedSince: 'Fri Aug 13 2021 00:00:00 GMT+0800 (Singapore Standard Time)',
1276+
ifModifiedSince: 'Thu, 12 Aug 2021 16:00:00 GMT',
12711277
ifNoneMatch: 'abc',
12721278
})
12731279
})

0 commit comments

Comments
 (0)