RangerMauve / hypercore-fetch

Implementation of Fetch that uses the Hyper SDK for loading p2p content
MIT License
37 stars 13 forks source link

PUT request to malformed url erases Hyperdrive #33

Closed josephmturner closed 1 year ago

josephmturner commented 1 year ago

Leaving out the slash between the public key and the path of a hyper:// url erases the Hyperdrive.

Let's say that I have generated the following public key from an alias: hyper://ef8db02d8e47fcd21b8708adacaadebb682586cde9c9d3257c32ed75d57d02a9/

fetch('hyper://ef8db02d8e47fcd21b8708adacaadebb682586cde9c9d3257c32ed75d57d02a9/example.txt', {method: 'PUT', body: 'Hello World'})

fetch('hyper://ef8db02d8e47fcd21b8708adacaadebb682586cde9c9d3257c32ed75d57d02a9/example.txt', {method: 'GET'})
// => 'Hello World'

fetch('hyper://ef8db02d8e47fcd21b8708adacaadebb682586cde9c9d3257c32ed75d57d02a9/', {method: 'GET'})
// => ["$/", "example.txt"]

// Attempt to update `example.txt`, but make a typo (notice missing "/" before "example.txt":
fetch('hyper://ef8db02d8e47fcd21b8708adacaadebb682586cde9c9d3257c32ed75d57d02a9example.txt', {method: 'GET'})
// This throws a HTTP/1.1 500 Internal Server Error with the following stack trace:
/*
Error: Missing Content-Type
at new Busboy (/snapshot/hyper-gateway/node_modules/busboy/lib/main.js:23:11)
at hyperFetch (/snapshot/hyper-gateway/node_modules/hypercore-fetch/index.js:390:26)
at async fetch (/snapshot/hyper-gateway/node_modules/make-fetch/index.js:37:9)
at async Server.<anonymous> (/snapshot/hyper-gateway/src/index.js:63:24)
*/

fetch('hyper://ef8db02d8e47fcd21b8708adacaadebb682586cde9c9d3257c32ed75d57d02a9/', {method: 'GET'})
// => ["$/"]
// Directory contents are now gone!

Is this behavior expected?

RangerMauve commented 1 year ago

Lets revisit this after the overhaul to hyperdrive 10

RangerMauve commented 1 year ago

I think this is no longer an issue.

josephmturner commented 1 year ago

Thank you! I can confirm this is no longer an issue.