Commit ca90b5ca0579ebdcc0635288bce4978e3fb200f5
Allow fetching blobs over https
cel committed on 5/9/2021, 1:41:22 AMParent: 6859afcdedef7118f29d6753ba4933fb14a08f21
Files changed
prelude/install.js | changed |
prelude/install.js | ||
---|---|---|
@@ -1,14 +1,19 @@ | ||
1 | 1 … | var os = require('os') |
2 | 2 … | var fs = require('fs') |
3 | 3 … | var zlib = require('zlib') |
4 | 4 … | var http = require('http') |
5 … | +var https = require('https') | |
5 | 6 … | var stream = require('stream') |
6 | 7 … | var path = require('path') |
7 | 8 … | var STORE_CONTENT = 1 |
8 | 9 … | |
9 | 10 … | var settings = JSON.parse(fs.readFileSync(3)) |
10 | 11 … | |
12 … | +function httpGet(url, cb) { | |
13 … | + return /^https:\/\//.test(url) ? https.get(url, cb) : http.get(url, cb) | |
14 … | +} | |
15 … | + | |
11 | 16 … | function ReadBlobs(links) { |
12 | 17 … | if (!Array.isArray(links)) throw new TypeError('blob links should be array') |
13 | 18 … | this.links = links |
14 | 19 … | stream.Readable.call(this, links) |
@@ -49,22 +54,22 @@ | ||
49 | 54 … | var onError = (err) => { |
50 | 55 … | if (err.code === 'ECONNRESET') { |
51 | 56 … | // retry after timeout |
52 | 57 … | setTimeout(() => { |
53 | - this.req = http.get(url, onResp).on('error', onError) | |
58 … | + this.req = httpGet(url, onResp).on('error', onError) | |
54 | 59 … | }, 1e3) |
55 | 60 … | } else if (err.code === 'ECONNREFUSED' && err.address === '127.0.0.1' |
56 | 61 … | && this.blobsBase.indexOf('localhost') > -1 |
57 | 62 … | ) { |
58 | 63 … | // sometimes localhost resolves to 127.0.0.1 but ssb-ws listens on ::1 |
59 | 64 … | this.blobsBase = this.blobsBase.replace('localhost', '[::1]') |
60 | 65 … | url = this.blobsBase + id |
61 | - http.get(url, onResp).on('error', onError) | |
66 … | + httpGet(url, onResp).on('error', onError) | |
62 | 67 … | } else { |
63 | 68 … | this.destroy(err) |
64 | 69 … | } |
65 | 70 … | } |
66 | - this.req = http.get(url, onResp).on('error', onError) | |
71 … | + this.req = httpGet(url, onResp).on('error', onError) | |
67 | 72 … | } |
68 | 73 … | |
69 | 74 … | function Meter() { |
70 | 75 … | stream.Transform.call(this) |
Built with git-ssb-web