mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 1150715 - Implement "Copy Request/Response Headers" context menu items. r=jsantell
This commit is contained in:
parent
42a52b8b3d
commit
fbaf1d4482
@ -598,6 +598,30 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy the raw request headers from the currently selected item.
|
||||
*/
|
||||
copyRequestHeaders: function() {
|
||||
let selected = this.selectedItem.attachment;
|
||||
let rawHeaders = selected.requestHeaders.rawHeaders.trim();
|
||||
if (Services.appinfo.OS !== "WINNT") {
|
||||
rawHeaders = rawHeaders.replace(/\r/g, "");
|
||||
}
|
||||
clipboardHelper.copyString(rawHeaders, document);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy the raw response headers from the currently selected item.
|
||||
*/
|
||||
copyResponseHeaders: function() {
|
||||
let selected = this.selectedItem.attachment;
|
||||
let rawHeaders = selected.responseHeaders.rawHeaders.trim();
|
||||
if (Services.appinfo.OS !== "WINNT") {
|
||||
rawHeaders = rawHeaders.replace(/\r/g, "");
|
||||
}
|
||||
clipboardHelper.copyString(rawHeaders, document);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy image as data uri.
|
||||
*/
|
||||
@ -1809,6 +1833,12 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
|
||||
let copyAsCurlElement = $("#request-menu-context-copy-as-curl");
|
||||
copyAsCurlElement.hidden = !selectedItem || !selectedItem.attachment.responseContent;
|
||||
|
||||
let copyRequestHeadersElement = $("#request-menu-context-copy-request-headers");
|
||||
copyRequestHeadersElement.hidden = !selectedItem || !selectedItem.attachment.requestHeaders;
|
||||
|
||||
let copyResponseHeadersElement = $("#response-menu-context-copy-response-headers");
|
||||
copyResponseHeadersElement.hidden = !selectedItem || !selectedItem.attachment.responseHeaders;
|
||||
|
||||
let copyResponse = $("#request-menu-context-copy-response");
|
||||
copyResponse.hidden = !selectedItem ||
|
||||
!selectedItem.attachment.responseContent ||
|
||||
|
@ -34,6 +34,13 @@
|
||||
<menuitem id="request-menu-context-copy-as-curl"
|
||||
label="&netmonitorUI.context.copyAsCurl;"
|
||||
oncommand="NetMonitorView.RequestsMenu.copyAsCurl();"/>
|
||||
<menuitem id="request-menu-context-copy-request-headers"
|
||||
label="&netmonitorUI.context.copyRequestHeaders;"
|
||||
accesskey="&netmonitorUI.context.copyRequestHeaders.accesskey;"
|
||||
oncommand="NetMonitorView.RequestsMenu.copyRequestHeaders();"/>
|
||||
<menuitem id="response-menu-context-copy-response-headers"
|
||||
label="&netmonitorUI.context.copyResponseHeaders;"
|
||||
oncommand="NetMonitorView.RequestsMenu.copyResponseHeaders();"/>
|
||||
<menuitem id="request-menu-context-copy-response"
|
||||
label="&netmonitorUI.context.copyResponse;"
|
||||
accesskey="&netmonitorUI.context.copyResponse.accesskey;"/>
|
||||
|
@ -54,6 +54,7 @@ skip-if= buildapp == 'mulet'
|
||||
[browser_net_copy_image_as_data_uri.js]
|
||||
[browser_net_copy_url.js]
|
||||
[browser_net_copy_response.js]
|
||||
[browser_net_copy_headers.js]
|
||||
[browser_net_copy_as_curl.js]
|
||||
skip-if = e10s # Bug 1091596
|
||||
[browser_net_cyrillic-01.js]
|
||||
|
63
browser/devtools/netmonitor/test/browser_net_copy_headers.js
Normal file
63
browser/devtools/netmonitor/test/browser_net_copy_headers.js
Normal file
@ -0,0 +1,63 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Tests if copying a request's request/response headers works.
|
||||
*/
|
||||
|
||||
add_task(function*() {
|
||||
|
||||
let [ aTab, aDebuggee, aMonitor ] = yield initNetMonitor(SIMPLE_URL);
|
||||
info("Starting test... ");
|
||||
|
||||
let { NetMonitorView } = aMonitor.panelWin;
|
||||
let { RequestsMenu } = NetMonitorView;
|
||||
|
||||
RequestsMenu.lazyUpdate = false;
|
||||
|
||||
aDebuggee.location.reload();
|
||||
yield waitForNetworkEvents(aMonitor, 1);
|
||||
|
||||
let requestItem = RequestsMenu.getItemAtIndex(0);
|
||||
RequestsMenu.selectedItem = requestItem;
|
||||
|
||||
let clipboard = null;
|
||||
|
||||
const EXPECTED_REQUEST_HEADERS = [
|
||||
requestItem.attachment.method + " " + SIMPLE_URL + " " + requestItem.attachment.httpVersion,
|
||||
"Host: example.com",
|
||||
"User-Agent: " + navigator.userAgent + "",
|
||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
"Accept-Language: " + navigator.languages.join(",") + ";q=0.5",
|
||||
"Accept-Encoding: gzip, deflate",
|
||||
"Connection: keep-alive",
|
||||
"Pragma: no-cache",
|
||||
"Cache-Control: no-cache"
|
||||
].join("\n");
|
||||
|
||||
RequestsMenu.copyRequestHeaders();
|
||||
clipboard = SpecialPowers.getClipboardData("text/unicode");
|
||||
// Sometimes, a "Cookie" header is left over from other tests. Remove it:
|
||||
clipboard = clipboard.replace(/Cookie: [^\n]+\n/, "");
|
||||
is(clipboard, EXPECTED_REQUEST_HEADERS, "Clipboard contains the currently selected item's request headers.");
|
||||
|
||||
const EXPECTED_RESPONSE_HEADERS = [
|
||||
requestItem.attachment.httpVersion + " " + requestItem.attachment.status + " " + requestItem.attachment.statusText,
|
||||
"Last-Modified: Sun, 3 May 2015 11:11:11 GMT",
|
||||
"Content-Type: text/html",
|
||||
"Content-Length: 465",
|
||||
"Connection: close",
|
||||
"Server: httpd.js",
|
||||
"Date: Sun, 3 May 2015 11:11:11 GMT"
|
||||
].join("\n");
|
||||
|
||||
RequestsMenu.copyResponseHeaders();
|
||||
clipboard = SpecialPowers.getClipboardData("text/unicode");
|
||||
// Fake the "Last-Modified" and "Date" headers because they will vary:
|
||||
clipboard = clipboard
|
||||
.replace(/Last-Modified: [^\n]+ GMT/, "Last-Modified: Sun, 3 May 2015 11:11:11 GMT")
|
||||
.replace(/Date: [^\n]+ GMT/, "Date: Sun, 3 May 2015 11:11:11 GMT");
|
||||
is(clipboard, EXPECTED_RESPONSE_HEADERS, "Clipboard contains the currently selected item's response headers.");
|
||||
|
||||
teardown(aMonitor).then(finish);
|
||||
});
|
@ -260,16 +260,16 @@
|
||||
- on the context menu that copies the selected request's url -->
|
||||
<!ENTITY netmonitorUI.context.copyUrl "Copy URL">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyUrl.accesskey): This is the access key
|
||||
- for the Copy URL menu item displayed in the context menu for a request -->
|
||||
<!ENTITY netmonitorUI.context.copyUrl.accesskey "C">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyAsCurl): This is the label displayed
|
||||
- on the context menu that copies the selected request as a cURL command.
|
||||
- The capitalization is part of the official name and should be used throughout all languages.
|
||||
- http://en.wikipedia.org/wiki/CURL -->
|
||||
<!ENTITY netmonitorUI.context.copyAsCurl "Copy as cURL">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyUrl.accesskey): This is the access key
|
||||
- for the Copy URL menu item displayed in the context menu for a request -->
|
||||
<!ENTITY netmonitorUI.context.copyUrl.accesskey "C">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyImageAsDataUri): This is the label displayed
|
||||
- on the context menu that copies the selected image as data uri -->
|
||||
<!ENTITY netmonitorUI.context.copyImageAsDataUri "Copy Image as Data URI">
|
||||
@ -282,10 +282,22 @@
|
||||
- on the context menu that copies the selected response as a string -->
|
||||
<!ENTITY netmonitorUI.context.copyResponse "Copy Response">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyImageAsDataUri.accesskey): This is the access key
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyRespose.accesskey): This is the access key
|
||||
- for the Copy Response menu item displayed in the context menu for a request -->
|
||||
<!ENTITY netmonitorUI.context.copyResponse.accesskey "R">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyRequestHeaders): This is the label displayed
|
||||
- on the context menu that copies the selected item's request headers -->
|
||||
<!ENTITY netmonitorUI.context.copyRequestHeaders "Copy Request Headers">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyRequestHeaders.accesskey): This is the access key
|
||||
- for the Copy Request Headers menu item displayed in the context menu for a request -->
|
||||
<!ENTITY netmonitorUI.context.copyRequestHeaders.accesskey "H">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyResponseHeaders): This is the label displayed
|
||||
- on the context menu that copies the selected item's response headers -->
|
||||
<!ENTITY netmonitorUI.context.copyResponseHeaders "Copy Response Headers">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.summary.editAndResend): This is the label displayed
|
||||
- on the button in the headers tab that opens a form to edit and resend the currently
|
||||
displayed request -->
|
||||
|
Loading…
Reference in New Issue
Block a user