Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(925)

Unified Diff: third_party/WebKit/Source/devtools/hosted_mode/request.js

Issue 2167413002: DevTools: implement proxy server for hosted mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address CL feedback Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/hosted_mode/request.js
diff --git a/third_party/WebKit/Source/devtools/hosted_mode/request.js b/third_party/WebKit/Source/devtools/hosted_mode/request.js
new file mode 100644
index 0000000000000000000000000000000000000000..ce8160954df2526ebbad43ce849d977f07374195
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/hosted_mode/request.js
@@ -0,0 +1,36 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var http = require("http");
+var https = require("https");
+var parseUrl = require("url").parse;
+
+function request(url)
lushnikov 2016/07/22 21:06:04 can we rename this into fetch? (to avoid conflicti
chenwilliam 2016/07/22 23:20:31 Done.
+{
+ return new Promise((resolve, reject) => {
+ var request;
+ var protocol = parseUrl(url).protocol;
+
+ if (protocol === "https:")
+ request = https.get(url, handleResponse);
+ else if (protocol === "http:")
lushnikov 2016/07/22 21:06:05 You never have any HTTP urls - let's remove this
chenwilliam 2016/07/22 23:20:31 Can't remove it because we make a request to http:
+ request = http.get(url, handleResponse);
+ else
+ reject(new Error(`Invalid protocol for url: ${url}`))
lushnikov 2016/07/22 21:06:04 you want to return here as well, (otherwise, the r
chenwilliam 2016/07/22 23:20:32 Done.
+
+ function handleResponse(response)
+ {
+ if (response.statusCode !== 200) {
+ return reject(new Error(`Request error: + ${response.statusCode}`));
lushnikov 2016/07/22 21:06:04 unfortunately, our style guide does not allow this
chenwilliam 2016/07/22 23:20:32 Done.
+ }
+ var body = "";
+ response.on("data", chunk => body += chunk);
+ response.on("end", () => resolve(body));
+ }
+
+ request.on("error", (err) => reject(err));
+ });
+}
+
+module.exports = request;

Powered by Google App Engine
This is Rietveld 408576698