hypercore-fetch 9.0.5 → 9.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +11 -7
  2. package/package.json +1 -1
  3. package/test.js +2 -0
package/index.js CHANGED
@@ -22,6 +22,7 @@ const MIME_TEXT_HTML = 'text/html; charset=utf-8'
22
22
  const MIME_EVENT_STREAM = 'text/event-stream; charset=utf-8'
23
23
 
24
24
  const HEADER_CONTENT_TYPE = 'Content-Type'
25
+ const HEADER_LAST_MODIFIED = 'Last-Modified'
25
26
 
26
27
  export const ERROR_KEY_NOT_CREATED = 'Must create key with POST before reading'
27
28
 
@@ -439,11 +440,12 @@ export default async function makeHyperFetch ({
439
440
  resHeaders.ETag = `${entry.seq}`
440
441
 
441
442
  const contentType = getMimeType(path)
442
- resHeaders['Content-Type'] = contentType
443
+ resHeaders[HEADER_CONTENT_TYPE] = contentType
443
444
 
444
- if (entry.metadata?.mtime) {
445
- const date = new Date(entry.metadata.mtime)
446
- resHeaders['Last-Modified'] = date.toUTCString()
445
+
446
+ if (entry?.value?.metadata?.mtime) {
447
+ const date = new Date(entry.value.metadata.mtime)
448
+ resHeaders[HEADER_LAST_MODIFIED] = date.toUTCString()
447
449
  }
448
450
 
449
451
  const size = entry.value.byteLength
@@ -549,6 +551,7 @@ async function serveFile (headers, drive, pathname) {
549
551
 
550
552
  const entry = await drive.entry(pathname)
551
553
 
554
+
552
555
  const resHeaders = {
553
556
  ETag: `${entry.seq}`,
554
557
  [HEADER_CONTENT_TYPE]: contentType,
@@ -556,9 +559,10 @@ async function serveFile (headers, drive, pathname) {
556
559
  Link: `<${fullURL}>; rel="canonical"`
557
560
  }
558
561
 
559
- if (entry.metadata?.mtime) {
560
- const date = new Date(entry.metadata.mtime)
561
- resHeaders['Last-Modified'] = date.toUTCString()
562
+
563
+ if (entry?.value?.metadata?.mtime) {
564
+ const date = new Date(entry.value.metadata.mtime)
565
+ resHeaders[HEADER_LAST_MODIFIED] = date.toUTCString()
562
566
  }
563
567
 
564
568
  const size = entry.value.blob.byteLength
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-fetch",
3
- "version": "9.0.5",
3
+ "version": "9.0.6",
4
4
  "description": "Implementation of Fetch that uses the Dat SDK for loading p2p content",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/test.js CHANGED
@@ -129,9 +129,11 @@ test('PUT file', async (t) => {
129
129
 
130
130
  const content = await uploadedContentResponse.text()
131
131
  const contentType = uploadedContentResponse.headers.get('Content-Type')
132
+ const lastModified = uploadedContentResponse.headers.get('Last-Modified')
132
133
 
133
134
  t.equal(contentType, 'text/plain; charset=utf-8', 'Content got expected mime type')
134
135
  t.equal(content, SAMPLE_CONTENT, 'Got uploaded content back out')
136
+ t.ok(lastModified, 'Last-Modified header got set')
135
137
  })
136
138
  test('PUT FormData', async (t) => {
137
139
  const created = await nextURL(t)