Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit e2adf7c

Browse files
yurydelendikjasonLaster
authored andcommitted
Return uneffected binary content and provide mime on /get endpoint (#1081)
1 parent abbaa1b commit e2adf7c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/devtools-launchpad/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "devtools-launchpad",
3-
"version": "0.0.130",
3+
"version": "0.0.131",
44
"license": "MPL-2.0",
55
"description": "The Launchpad makes it easy to build a developer tool for Firefox, Chrome, and Node.",
66
"repository": {
@@ -66,6 +66,7 @@
6666
"immutable": "^3.7.6",
6767
"json-loader": "^0.5.4",
6868
"md5": "^2.2.1",
69+
"mime-types": "^2.1.18",
6970
"minimist": "^1.2.0",
7071
"mustache": "^2.2.1",
7172
"node-static": "^0.7.7",

packages/devtools-launchpad/src/development-server.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
55

6+
/* eslint-env node */
7+
68
require("babel-register");
79

810
const path = require("path");
@@ -27,6 +29,7 @@ const {
2729
const isDevelopment = require("devtools-environment").isDevelopment;
2830
const { handleLaunchRequest } = require("./server/launch");
2931
const NODE_VERSION = require("../package.json").engines.node;
32+
const mime = require("mime-types");
3033
let root;
3134

3235
function httpOrHttpsGet(url, onResponse) {
@@ -38,11 +41,12 @@ function httpOrHttpsGet(url, onResponse) {
3841
response.emit("statusCode", new Error(response.statusCode));
3942
return onResponse("{}");
4043
}
41-
let body = "";
42-
response.on("data", (d) => {
43-
body += d;
44+
const contentType = response.headers["content-type"];
45+
let body = Buffer.alloc(0);
46+
response.on("data", (data) => {
47+
body = Buffer.concat([body, data]);
4448
});
45-
response.on("end", () => onResponse(body));
49+
response.on("end", () => onResponse({ body, contentType }));
4650

4751
return undefined;
4852
});
@@ -80,13 +84,20 @@ function handleNetworkRequest(req, res) {
8084
const url = req.query.url;
8185
if (url.indexOf("file://") === 0) {
8286
const _path = url.replace("file://", "");
83-
res.json(JSON.parse(fs.readFileSync(_path, "utf8")));
87+
const mimeType = mime.lookup(_path);
88+
if (mimeType) {
89+
res.set("Content-Type", mimeType);
90+
}
91+
res.send(fs.readFileSync(_path));
8492
} else {
85-
const httpReq = httpOrHttpsGet(req.query.url, body => {
93+
const httpReq = httpOrHttpsGet(req.query.url, ({ body, contentType }) => {
94+
if (contentType) {
95+
res.set("Content-Type", contentType);
96+
}
8697
try {
8798
res.send(body);
8899
} catch (e) {
89-
res.status(500).send("Malformed json");
100+
res.status(500).send(`Network error: ${e}`);
90101
}
91102
});
92103

0 commit comments

Comments
 (0)