1 parent e0ee057 commit 60402adCopy full SHA for 60402ad
3 files changed
lib/handlers/get.mjs
@@ -76,19 +76,22 @@ export default async function handler (req, res, next) {
76
let container
77
let contentRange
78
let chunksize
79
+ let mtime
80
81
if (ret) {
82
stream = ret.stream
83
contentType = ret.contentType
84
container = ret.container
85
contentRange = ret.contentRange
86
chunksize = ret.chunksize
87
+ mtime = ret.mtime
88
}
89
90
// Till here it must exist
91
if (!includeBody) {
92
debug('HEAD only')
93
res.setHeader('Content-Type', ret.contentType)
94
+ if (mtime) res.setHeader('Last-Modified', mtime.toUTCString())
95
return res.status(200).send('OK')
96
97
@@ -118,7 +121,8 @@ export default async function handler (req, res, next) {
118
121
// If request accepts the content-type we found
119
122
if (stream && negotiator.mediaType([contentType])) {
120
123
let headers = {
- 'Content-Type': contentType
124
+ 'Content-Type': contentType,
125
+ ...(mtime && { 'Last-Modified': mtime.toUTCString() })
126
127
128
if (contentRange) {
@@ -160,6 +164,9 @@ export default async function handler (req, res, next) {
160
164
headers
161
165
})) return
162
166
res.setHeader('Content-Type', possibleRDFType)
167
+ if (mtime) {
168
+ res.setHeader('Last-Modified', mtime.toUTCString())
169
+ }
163
170
res.send(data)
171
return next()
172
} catch (err) {
lib/ldp.mjs
@@ -451,7 +451,7 @@ class LDP {
451
452
453
if (!options.includeBody) {
454
- return { stream: stats, contentType, container: stats.isDirectory() }
+ return { stream: stats, contentType, container: stats.isDirectory(), mtime: stats.mtime }
455
456
457
if (stats.isDirectory()) {
@@ -465,7 +465,7 @@ class LDP {
465
throw err
466
467
const stream = stringToStream(data)
468
- return { stream, contentType, container: true }
+ return { stream, contentType, container: true, mtime: stats.mtime }
469
} else {
470
let chunksize, contentRange, start, end
471
if (options.range) {
@@ -487,7 +487,7 @@ class LDP {
487
})
488
.on('open', function () {
489
debug.handlers(`GET -- Reading ${pathLocal}`)
490
- return resolve({ stream, contentType, container: false, contentRange, chunksize })
+ return resolve({ stream, contentType, container: false, contentRange, chunksize, mtime: stats.mtime })
491
492
}))
493
test/integration/header-test.mjs
@@ -68,6 +68,23 @@ describe('Header handler', () => {
68
69
70
71
+ describe('Last-Modified', () => {
72
+ describeHeaderTest('read/append for the public', {
73
+ resource: '/public-ra',
74
+ headers: {
75
+ 'Last-Modified': /^\w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/
+ })
+
+ describe('on a HEAD request', () => {
+ it('has a Last-Modified header', async () => {
+ const { headers } = await request.head('/public-ra')
+ expect(headers).to.have.property('last-modified')
+ expect(headers['last-modified']).to.match(/^\w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/)
function describeHeaderTest (label, { resource, headers }) {
describe(`a resource that is ${label}`, () => {
// Retrieve the response headers
0 commit comments