Giter Club home page Giter Club logo

multiblob-http's Introduction

multiblob-http

serve content-addressed blobs over http. see use with multiblob

example

var MultiBlob = require('multiblob')
var MultiBlobHttp = require('multiblob-http')
var http = require('http')

var dir = where_files_go //set this.

var blobs = MultiBlob(dir)

http.createServer(MultiBlobHttp(blobs, '/blobs')).listen(8000)

this will return an http handler (compatible with express middleware) that will handle requests

  • GET /blobs/get/{id}
  • POST /blobs/add (which will respond with the hash)

you can also set a different prefix, but I use /blobs

http api

GET /get/{id}

retrive blob with hash {id}

range requests rfc 7233 are supported, This enables better video playback in browsers. Browsers tend to refuse to loop videos otherwise and seeking in videos requires range requests. It's also great for extracting embedded thumbnails from JPEGs etc.

POST /add

posts to add do not require to have a hash, but will respond with the hash. (TODO: take a POST to /add/{id} and error if received content did not have that hash)

caching && headers

multiblobs-http provides the correct headers to make serving content-addressed files as efficient as possible.

First the the etag header is set to the hash and the expires header is set to a year in the future. Ideally, the browser shouldn't request this resource again for a whole year. Probably it might revalidate it when someone uses ctrl-R to reload the page. When it does, it will request with if-none-modified set to the hash. Since content-addressed files are never modified, the server immediately responds with 304 (not modified)

the content-length header is always used unless "opts.size=false". This way, if a connection fails somehow, or there is an error later, the browser should detect it.

Of course, it would be way better if browsers just understood content-hashes. But, we have to play the hand we where delt, and multiblob-http makes the most of the broken web we live in.

License

MIT

multiblob-http's People

Contributors

dominictarr avatar regular avatar ssured avatar staltz avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

multiblob-http's Issues

SSB Server crash when using `blobs.size()`

Getting this with ssb-server master + ssb-ws latest. This is happening when connecting to ws:/localhost:8989~shs:pPnZTDg8XedTXwgRqjMa5CGmDTwBTSuMzdqlAvNI8ck= with https://github.com/arj03/ssb-browser-demo. No blobs are loading client side either, so could be something to do with the frontend.

/home/tim/projects/ssb-server/node_modules/multiblob-http/index.js:62
      blobs.size(hash, function (err, size) {
            ^

TypeError: Cannot read property 'size' of undefined
    at /home/tim/projects/ssb-server/node_modules/multiblob-http/index.js:62:13
    at /home/tim/projects/ssb-server/node_modules/ssb-ws/blobs.js:36:15
    at /home/tim/projects/ssb-server/node_modules/ssb-blobs/inject.js:292:11
    at next (/home/tim/projects/ssb-server/node_modules/ssb-blobs/inject.js:170:7)
    at /home/tim/projects/ssb-server/node_modules/ssb-blobs/inject.js:159:13
    at /home/tim/projects/ssb-server/node_modules/multiblob/index.js:124:20
    at continuation (/home/tim/projects/ssb-server/node_modules/continuable-list/index.js:24:25)
    at /home/tim/projects/ssb-server/node_modules/multiblob/index.js:94:9
    at done (/home/tim/projects/ssb-server/node_modules/multiblob/util.js:88:38)
    at FSReqWrap.oncomplete (fs.js:154:5)

Investigating root cause now.

Crash on "no blob"

in scuttlebot with ssb-ws plugin, with patchbay as client:

GET /blobs/get/&qjeAs8+uMXLlyovT4JnEpMwTNDx/QXHfOl2nv2u0VCM=.sha256
GET /blobs/get/&qjeAs8+uMXLlyovT4JnEpMwTNDx/QXHfOl2nv2u0VCM=.sha256
GET /blobs/get/&Zm/6FJsLdopu3zD1Z9i+uUhzei+t5TFbJV9sseFWpMc=.sha256
GET /blobs/get/&Zm/6FJsLdopu3zD1Z9i+uUhzei+t5TFbJV9sseFWpMc=.sha256
Error: no blob:&qjeAs8+uMXLlyovT4JnEpMwTNDx/QXHfOl2nv2u0VCM=.sha256
    at /usr/local/src/ssb-ws/node_modules/multiblob-http/index.js:39:23
    at /usr/local/src/scuttlebot/node_modules/multiblob/index.js:141:15
    at continuation (/usr/local/src/scuttlebot/node_modules/cont/node_modules/continuable-para/node_modules/continuable-list/index.js:24:25)
    at /usr/local/src/scuttlebot/node_modules/multiblob/index.js:114:9
    at done (/usr/local/src/scuttlebot/node_modules/multiblob/index.js:41:38)
    at FSReqWrap.oncomplete (fs.js:82:15)
_http_outgoing.js:403
    throw new Error('Can\'t render headers after they are sent to the client.');
    ^

Error: Can't render headers after they are sent to the client.
    at ServerResponse.OutgoingMessage._renderHeaders (_http_outgoing.js:403:11)
    at ServerResponse.writeHead (_http_server.js:184:20)
    at /usr/local/src/ssb-ws/node_modules/multiblob-http/index.js:41:13
    at /usr/local/src/scuttlebot/node_modules/multiblob/index.js:141:15
    at continuation (/usr/local/src/scuttlebot/node_modules/cont/node_modules/continuable-para/node_modules/continuable-list/index.js:24:25)
    at /usr/local/src/scuttlebot/node_modules/multiblob/index.js:114:9
    at done (/usr/local/src/scuttlebot/node_modules/multiblob/index.js:41:38)
    at FSReqWrap.oncomplete (fs.js:82:15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.