git ssb

0+

cel-desktop / ssb-pkg



Commit ca90b5ca0579ebdcc0635288bce4978e3fb200f5

Allow fetching blobs over https

cel committed on 5/9/2021, 1:41:22 AM
Parent: 6859afcdedef7118f29d6753ba4933fb14a08f21

Files changed

prelude/install.jschanged
prelude/install.jsView
@@ -1,14 +1,19 @@
11 var os = require('os')
22 var fs = require('fs')
33 var zlib = require('zlib')
44 var http = require('http')
5 +var https = require('https')
56 var stream = require('stream')
67 var path = require('path')
78 var STORE_CONTENT = 1
89
910 var settings = JSON.parse(fs.readFileSync(3))
1011
12 +function httpGet(url, cb) {
13 + return /^https:\/\//.test(url) ? https.get(url, cb) : http.get(url, cb)
14 +}
15 +
1116 function ReadBlobs(links) {
1217 if (!Array.isArray(links)) throw new TypeError('blob links should be array')
1318 this.links = links
1419 stream.Readable.call(this, links)
@@ -49,22 +54,22 @@
4954 var onError = (err) => {
5055 if (err.code === 'ECONNRESET') {
5156 // retry after timeout
5257 setTimeout(() => {
53- this.req = http.get(url, onResp).on('error', onError)
58 + this.req = httpGet(url, onResp).on('error', onError)
5459 }, 1e3)
5560 } else if (err.code === 'ECONNREFUSED' && err.address === '127.0.0.1'
5661 && this.blobsBase.indexOf('localhost') > -1
5762 ) {
5863 // sometimes localhost resolves to 127.0.0.1 but ssb-ws listens on ::1
5964 this.blobsBase = this.blobsBase.replace('localhost', '[::1]')
6065 url = this.blobsBase + id
61- http.get(url, onResp).on('error', onError)
66 + httpGet(url, onResp).on('error', onError)
6267 } else {
6368 this.destroy(err)
6469 }
6570 }
66- this.req = http.get(url, onResp).on('error', onError)
71 + this.req = httpGet(url, onResp).on('error', onError)
6772 }
6873
6974 function Meter() {
7075 stream.Transform.call(this)

Built with git-ssb-web