зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1583397 - Ensures headers are fetched before trying to resend request. r=Honza
Differential Revision: https://phabricator.services.mozilla.com/D61381 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c73d875661
Коммит
264529e383
|
@ -19,6 +19,9 @@ const {
|
|||
getSelectedRequest,
|
||||
getRequestById,
|
||||
} = require("devtools/client/netmonitor/src/selectors/index");
|
||||
const {
|
||||
fetchNetworkUpdatePacket,
|
||||
} = require("devtools/client/netmonitor/src/utils/request-utils");
|
||||
|
||||
function addRequest(id, data, batch) {
|
||||
return {
|
||||
|
@ -73,7 +76,7 @@ function cloneSelectedRequest() {
|
|||
* Send a new HTTP request using the data in the custom request form.
|
||||
*/
|
||||
function sendCustomRequest(connector, requestId = null) {
|
||||
return (dispatch, getState) => {
|
||||
return async (dispatch, getState) => {
|
||||
let request;
|
||||
if (requestId) {
|
||||
request = getRequestById(getState(), requestId);
|
||||
|
@ -85,6 +88,15 @@ function sendCustomRequest(connector, requestId = null) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Fetch request headers and post data from the backend.
|
||||
await fetchNetworkUpdatePacket(connector.requestData, request, [
|
||||
"requestHeaders",
|
||||
"requestPostData",
|
||||
]);
|
||||
|
||||
// Reload the request from the store to get the headers.
|
||||
request = getRequestById(getState(), request.id);
|
||||
|
||||
// Send a new HTTP request using the data in the custom request form
|
||||
const data = {
|
||||
cause: request.cause,
|
||||
|
@ -92,9 +104,11 @@ function sendCustomRequest(connector, requestId = null) {
|
|||
method: request.method,
|
||||
httpVersion: request.httpVersion,
|
||||
};
|
||||
|
||||
if (request.requestHeaders) {
|
||||
data.headers = request.requestHeaders.headers;
|
||||
}
|
||||
|
||||
if (request.requestPostData) {
|
||||
data.body = request.requestPostData.postData.text;
|
||||
}
|
||||
|
|
|
@ -221,6 +221,7 @@ function cloneRequest(state, id) {
|
|||
requestHeaders: clonedRequest.requestHeaders,
|
||||
requestPostData: clonedRequest.requestPostData,
|
||||
requestPostDataAvailable: clonedRequest.requestPostDataAvailable,
|
||||
requestHeadersAvailable: clonedRequest.requestHeadersAvailable,
|
||||
isCustom: true,
|
||||
};
|
||||
|
||||
|
|
|
@ -192,6 +192,7 @@ skip-if = os == 'win' # bug 1391264
|
|||
[browser_net_resend_cors.js]
|
||||
[browser_net_resend_csp.js]
|
||||
[browser_net_resend_headers.js]
|
||||
[browser_net_resend_hidden_headers.js]
|
||||
[browser_net_resend_xhr.js]
|
||||
[browser_net_resend.js]
|
||||
[browser_net_security-details.js]
|
||||
|
|
|
@ -31,6 +31,8 @@ add_task(async function() {
|
|||
EventUtils.sendMouseEvent({ type: "contextmenu" }, imgRequest);
|
||||
getContextMenuItem(monitor, "request-list-context-resend-only").click();
|
||||
|
||||
await performRequests(monitor, tab, 1);
|
||||
|
||||
// Selects request that was resent
|
||||
const selReq = getSelectedRequest(store.getState());
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Test that custom request headers are sent even without clicking on the original request (bug 1583397)
|
||||
*/
|
||||
|
||||
add_task(async function() {
|
||||
const { monitor } = await initNetMonitor(SIMPLE_URL);
|
||||
info("Starting test... ");
|
||||
|
||||
const { store, windowRequire, connector } = monitor.panelWin;
|
||||
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
|
||||
const { sendHTTPRequest } = connector;
|
||||
|
||||
const { getSortedRequests } = windowRequire(
|
||||
"devtools/client/netmonitor/src/selectors/index"
|
||||
);
|
||||
|
||||
store.dispatch(Actions.batchEnable(false));
|
||||
|
||||
const requestUrl = SIMPLE_SJS;
|
||||
const requestHeaders = [
|
||||
{ name: "Accept", value: "application/vnd.example+json" },
|
||||
];
|
||||
|
||||
const originalRequest = waitForNetworkEvents(monitor, 1);
|
||||
sendHTTPRequest({
|
||||
url: requestUrl,
|
||||
method: "GET",
|
||||
headers: requestHeaders,
|
||||
cause: {
|
||||
loadingDocumentUri: "http://example.com",
|
||||
stacktraceAvailable: true,
|
||||
type: "xhr",
|
||||
},
|
||||
});
|
||||
await originalRequest;
|
||||
|
||||
info("Sent original request");
|
||||
|
||||
const originalItem = getSortedRequests(store.getState())[0];
|
||||
|
||||
store.dispatch(Actions.cloneRequest(originalItem.id));
|
||||
|
||||
const clonedRequest = waitForNetworkEvents(monitor, 1);
|
||||
|
||||
store.dispatch(Actions.sendCustomRequest(connector, originalItem.id));
|
||||
|
||||
await clonedRequest;
|
||||
|
||||
info("Resent request");
|
||||
|
||||
let clonedItem = getSortedRequests(store.getState())[1];
|
||||
|
||||
await waitForRequestData(store, ["requestHeaders"], clonedItem.id);
|
||||
|
||||
clonedItem = getSortedRequests(store.getState())[1];
|
||||
|
||||
for (const { name, value } of clonedItem.requestHeaders.headers) {
|
||||
info(`Request header: ${name}: ${value}`);
|
||||
}
|
||||
|
||||
function hasRequestHeader(name, value) {
|
||||
const { headers } = clonedItem.requestHeaders;
|
||||
return headers.some(h => h.name === name && h.value === value);
|
||||
}
|
||||
|
||||
function hasNotRequestHeader(name) {
|
||||
const { headers } = clonedItem.requestHeaders;
|
||||
return headers.every(h => h.name !== name);
|
||||
}
|
||||
|
||||
for (const { name, value } of requestHeaders) {
|
||||
ok(hasRequestHeader(name, value), `The ${name} header has the right value`);
|
||||
}
|
||||
|
||||
// Check that the Cookie header was not added silently (i.e., that the request is
|
||||
// anonymous.
|
||||
for (const name of ["Cookie"]) {
|
||||
ok(hasNotRequestHeader(name), `The ${name} header is not present`);
|
||||
}
|
||||
|
||||
return teardown(monitor);
|
||||
});
|
|
@ -31,6 +31,8 @@ add_task(async function() {
|
|||
EventUtils.sendMouseEvent({ type: "contextmenu" }, firstRequest);
|
||||
getContextMenuItem(monitor, "request-list-context-resend-only").click();
|
||||
|
||||
await performRequests(monitor, tab, 2);
|
||||
|
||||
// Selects request that was resent
|
||||
const selectedRequest = getSelectedRequest(store.getState());
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче