hypercore-fetch 9.0.2 → 9.0.3
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.
- package/index.js +9 -3
- package/package.json +1 -1
- package/test.js +2 -0
package/index.js
CHANGED
|
@@ -356,11 +356,12 @@ export default async function makeHyperFetch ({
|
|
|
356
356
|
const isDirectory = pathname.endsWith('/')
|
|
357
357
|
|
|
358
358
|
const drive = await getDrive(`hyper://${hostname}`)
|
|
359
|
+
const fullURL = new URL(pathname, drive.core.url).href
|
|
359
360
|
|
|
360
361
|
const resHeaders = {
|
|
361
362
|
ETag: `${drive.version}`,
|
|
362
363
|
'Accept-Ranges': 'bytes',
|
|
363
|
-
Link: `<${
|
|
364
|
+
Link: `<${fullURL}>; rel="canonical"`
|
|
364
365
|
}
|
|
365
366
|
|
|
366
367
|
if (isDirectory) {
|
|
@@ -415,6 +416,8 @@ export default async function makeHyperFetch ({
|
|
|
415
416
|
return { status: 404, body: 'Not Found' }
|
|
416
417
|
}
|
|
417
418
|
|
|
419
|
+
resHeaders.Link = new URL(path, drive.core.url).href
|
|
420
|
+
|
|
418
421
|
resHeaders.ETag = `${entry.seq}`
|
|
419
422
|
|
|
420
423
|
const contentType = getMimeType(path)
|
|
@@ -459,11 +462,12 @@ export default async function makeHyperFetch ({
|
|
|
459
462
|
const isDirectory = pathname.endsWith('/')
|
|
460
463
|
|
|
461
464
|
const drive = await getDrive(`hyper://${hostname}`)
|
|
465
|
+
const fullURL = new URL(pathname, drive.core.url).href
|
|
462
466
|
|
|
463
467
|
if (isDirectory) {
|
|
464
468
|
const resHeaders = {
|
|
465
469
|
ETag: `${drive.version}`,
|
|
466
|
-
Link: `<${
|
|
470
|
+
Link: `<${fullURL}>; rel="canonical"`
|
|
467
471
|
}
|
|
468
472
|
|
|
469
473
|
const entries = await listEntries(drive, pathname)
|
|
@@ -523,13 +527,15 @@ async function serveFile (headers, drive, pathname) {
|
|
|
523
527
|
const isRanged = headers.get('Range') || ''
|
|
524
528
|
const contentType = getMimeType(pathname)
|
|
525
529
|
|
|
530
|
+
const fullURL = new URL(pathname, drive.core.url).href
|
|
531
|
+
|
|
526
532
|
const entry = await drive.entry(pathname)
|
|
527
533
|
|
|
528
534
|
const resHeaders = {
|
|
529
535
|
ETag: `${entry.seq}`,
|
|
530
536
|
[HEADER_CONTENT_TYPE]: contentType,
|
|
531
537
|
'Accept-Ranges': 'bytes',
|
|
532
|
-
Link: `<${
|
|
538
|
+
Link: `<${fullURL}>; rel="canonical"`
|
|
533
539
|
}
|
|
534
540
|
|
|
535
541
|
if (entry.metadata?.mtime) {
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -72,7 +72,9 @@ test('Quick check', async (t) => {
|
|
|
72
72
|
|
|
73
73
|
const content = await uploadedContentResponse.text()
|
|
74
74
|
const contentType = uploadedContentResponse.headers.get('Content-Type')
|
|
75
|
+
const contentLink = uploadedContentResponse.headers.get('Link')
|
|
75
76
|
|
|
77
|
+
t.match(contentLink, /^<hyper:\/\/[0-9a-z]{52}\/example.txt>; rel="canonical"$/, 'Link header includes both public key and path.')
|
|
76
78
|
t.equal(contentType, 'text/plain; charset=utf-8', 'Content got expected mime type')
|
|
77
79
|
t.equal(content, SAMPLE_CONTENT, 'Got uploaded content back out')
|
|
78
80
|
|