RangerMauve / hypercore-fetch

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

How to check that a node is writable #60

Closed josephmturner closed 1 year ago

josephmturner commented 1 year ago

Besides attempting to write or delete a file from a hyperdrive, is there a way to check that a drive is writable?

josephmturner commented 1 year ago

Perhaps we could add a dummy file inside of the special folder, like hyper://public-key/$/writable. HEAD requests to that url would return status 200 (204?) if the session is writable or 403 if not.

RangerMauve commented 1 year ago

Generally in the past I did this by setting the allowed methods header in the HEAD request.

Maybe we can add the Allow header in any requests which can contain PUT/POST to.

That way one can check if a given drive is writable by doing a HEAD on the root, then checking if the headers.Allow list contains PUT.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Allow

Also down to have a proper error code returned if one does a PUT on a non writable drive.

RangerMauve commented 1 year ago

Thinking of using 405 for saying "You can't POST here".

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405