Diff
Modified: trunk/LayoutTests/ChangeLog (140390 => 140391)
--- trunk/LayoutTests/ChangeLog 2013-01-22 08:10:10 UTC (rev 140390)
+++ trunk/LayoutTests/ChangeLog 2013-01-22 08:13:08 UTC (rev 140391)
@@ -1,3 +1,13 @@
+2013-01-22 Sergey Ryazanov <[email protected]>
+
+ Web Inspector: Show requests in `curl` syntax in DevTools → Network → Headers
+ https://bugs.webkit.org/show_bug.cgi?id=107276
+
+ Reviewed by Pavel Feldman.
+
+ * inspector/curl-command-expected.txt: Added.
+ * inspector/curl-command.html: Added.
+
2013-01-21 Kent Tamura <[email protected]>
Date selection from calendar picker should dispatch 'input' event in addition to 'change' event
Added: trunk/LayoutTests/inspector/curl-command-expected.txt (0 => 140391)
--- trunk/LayoutTests/inspector/curl-command-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/curl-command-expected.txt 2013-01-22 08:13:08 UTC (rev 140391)
@@ -0,0 +1,7 @@
+Tests curl command generation
+
+curl "http://example.org/path"
+curl "http://example.org/path" --data-binary "123"
+curl "http://example.org/path" -H "Content-Type: application/x-www-form-urlencoded" --data "1&b"
+curl "http://example.org/path" -H "Content-Type: application/json" --data-binary "{\"a\":1}"
+
Added: trunk/LayoutTests/inspector/curl-command.html (0 => 140391)
--- trunk/LayoutTests/inspector/curl-command.html (rev 0)
+++ trunk/LayoutTests/inspector/curl-command.html 2013-01-22 08:13:08 UTC (rev 140391)
@@ -0,0 +1,45 @@
+<html>
+<head>
+<script src=""
+<script type="text/_javascript_">
+
+var test = function()
+{
+ var logView = WebInspector.panel("network")._networkLogView;
+
+ function newRequest(headers, data)
+ {
+ var request = new WebInspector.NetworkRequest(0, "http://example.org/path", 0, 0, 0);
+ request.requestMethod = data ? "POST" : "GET";
+ var headerList = [];
+ if (headers) {
+ for (var i in headers)
+ headerList.push({name: i, value: headers[i]});
+ }
+ if (data) {
+ headerList.push({name: "Content-Length", value: data.length});
+ request.requestFormData = data;
+ }
+ request.requestHeaders = headerList;
+ return request;
+ }
+
+ function dumpRequest(headers, data)
+ {
+ InspectorTest.addResult(logView._generateCurlCommand(newRequest(headers, data)));
+ }
+
+ dumpRequest({})
+ dumpRequest({}, "123");
+ dumpRequest({"Content-Type": "application/x-www-form-urlencoded"}, "1&b");
+ dumpRequest({"Content-Type": "application/json"}, "{\"a\":1}");
+
+ InspectorTest.completeTest();
+}
+
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests curl command generation</p>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (140390 => 140391)
--- trunk/Source/WebCore/ChangeLog 2013-01-22 08:10:10 UTC (rev 140390)
+++ trunk/Source/WebCore/ChangeLog 2013-01-22 08:13:08 UTC (rev 140391)
@@ -1,3 +1,15 @@
+2013-01-22 Sergey Ryazanov <[email protected]>
+
+ Web Inspector: Show requests in `curl` syntax in DevTools → Network → Headers
+ https://bugs.webkit.org/show_bug.cgi?id=107276
+
+ Reviewed by Pavel Feldman.
+
+ Test: inspector/curl-command.html
+
+ * inspector/front-end/NetworkPanel.js:
+ (WebInspector.NetworkLogView.prototype._generateCurlCommand):
+
2013-01-22 Yury Semikhatsky <[email protected]>
Web Inspector: reuse JS heap profiler UI for native heap graph representaion
Modified: trunk/Source/WebCore/English.lproj/localizedStrings.js (140390 => 140391)
--- trunk/Source/WebCore/English.lproj/localizedStrings.js 2013-01-22 08:10:10 UTC (rev 140390)
+++ trunk/Source/WebCore/English.lproj/localizedStrings.js 2013-01-22 08:13:08 UTC (rev 140391)
@@ -133,6 +133,8 @@
localizedStrings["Copy Request Headers"] = "Copy Request Headers";
localizedStrings["Copy response headers"] = "Copy response headers";
localizedStrings["Copy Response Headers"] = "Copy Response Headers";
+localizedStrings["Copy as curl"] = "Copy as curl";
+localizedStrings["Copy as Curl"] = "Copy as Curl";
localizedStrings["Copy XPath"] = "Copy XPath";
localizedStrings["Web SQL"] = "Web SQL";
localizedStrings["DNS Lookup"] = "DNS Lookup";
Modified: trunk/Source/WebCore/inspector/front-end/NetworkPanel.js (140390 => 140391)
--- trunk/Source/WebCore/inspector/front-end/NetworkPanel.js 2013-01-22 08:10:10 UTC (rev 140390)
+++ trunk/Source/WebCore/inspector/front-end/NetworkPanel.js 2013-01-22 08:13:08 UTC (rev 140391)
@@ -1001,6 +1001,7 @@
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy request headers" : "Copy Request Headers"), this._copyRequestHeaders.bind(this, request));
if (request.responseHeadersText)
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy response headers" : "Copy Response Headers"), this._copyResponseHeaders.bind(this, request));
+ contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy as curl" : "Copy as Curl"), this._copyCurlCommand.bind(this, request));
}
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy all as HAR" : "Copy All as HAR"), this._copyAll.bind(this));
@@ -1054,6 +1055,14 @@
InspectorFrontendHost.copyText(request.responseHeadersText);
},
+ /**
+ * @param {WebInspector.NetworkRequest} request
+ */
+ _copyCurlCommand: function(request)
+ {
+ InspectorFrontendHost.copyText(this._generateCurlCommand(request));
+ },
+
_exportAll: function()
{
var filename = WebInspector.inspectedPageDomain + ".har";
@@ -1322,6 +1331,56 @@
this._highlightedNode = node;
},
+ /**
+ * @param {WebInspector.NetworkRequest} request
+ * @return {string}
+ */
+ _generateCurlCommand: function(request)
+ {
+ var command = ["curl"];
+ var ignoredHeaders = {};
+
+ function escape(str)
+ {
+ return "\"" + str.replace(/\\/g, "\\\\")
+ .replace(/\"/g, "\\\"")
+ .replace(/\$/g, "\\$")
+ .replace(/\n/g, "\\\n")
+ .replace(/\`/g, "\\\`") + "\"";
+ }
+ command.push(escape(request.url));
+
+ var inferredMethod = "GET";
+ var data = ""
+ var requestContentType = request.requestContentType();
+ if (requestContentType && requestContentType.startsWith("application/x-www-form-urlencoded") && request.requestFormData) {
+ data.push("--data");
+ data.push(escape(request.requestFormData));
+ ignoredHeaders["Content-Length"] = true;
+ inferredMethod = "POST";
+ } else if (request.requestFormData) {
+ data.push("--data-binary");
+ data.push(escape(request.requestFormData));
+ ignoredHeaders["Content-Length"] = true;
+ inferredMethod = "POST";
+ }
+
+ if (request.requestMethod !== inferredMethod) {
+ command.push("-X");
+ command.push(request.requestMethod);
+ }
+
+ for (var i = 0; i < request.requestHeaders.length; i++) {
+ var header = request.requestHeaders[i];
+ if (header.name in ignoredHeaders)
+ continue;
+ command.push("-H");
+ command.push(escape(header.name + ": " + header.value));
+ }
+ command = command.concat(data);
+ return command.join(" ");
+ },
+
__proto__: WebInspector.View.prototype
}