http rewrite (actually works this time!!1!) (#1257)

* rewrite http

* browser fun

* all the mimes dammit

* i need a newline

* whoops

* forgot about this

* use promises and HTTPRequest.method

* fluent

* move httpclient to external module

* branding

* middleware

* revert middleware
This commit is contained in:
Gus Caplan
2017-04-01 02:04:01 -05:00
committed by Crawl
parent a4e0af2e45
commit cb3f6d9646
5 changed files with 18 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
const path = require('path');
const fs = require('fs');
const request = require('superagent');
const snekfetch = require('snekfetch');
const Constants = require('../util/Constants');
const convertToBuffer = require('../util/Util').convertToBuffer;
@@ -211,11 +211,9 @@ class ClientDataResolver {
if (typeof resource === 'string') {
return new Promise((resolve, reject) => {
if (/^https?:\/\//.test(resource)) {
const req = request.get(resource).set('Content-Type', 'blob');
if (this.client.browser) req.responseType('arraybuffer');
req.end((err, res) => {
snekfetch.get(resource)
.end((err, res) => {
if (err) return reject(err);
if (this.client.browser) return resolve(convertToBuffer(res.xhr.response));
if (!(res.body instanceof Buffer)) return reject(new TypeError('The response body isn\'t a Buffer.'));
return resolve(res.body);
});