Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setRequestHeader(header, value) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
if (arguments.length !== 2) {
throw new TypeError("2 arguments required for setRequestHeader");
}
header = conversions.ByteString(header);
value = conversions.ByteString(value);
if (this.readyState !== XMLHttpRequest.OPENED || properties.send) {
throw new DOMException("The object is in an invalid state.", "InvalidStateError");
}
value = normalizeHeaderValue(value);
if (!tokenRegexp.test(header) || !fieldValueRegexp.test(value)) {
throw new DOMException("The string did not match the expected pattern.", "SyntaxError");
}
const lcHeader = header.toLowerCase();
if (forbiddenRequestHeaders.has(lcHeader) || lcHeader.startsWith("sec-") || lcHeader.startsWith("proxy-")) {
return;
setRequestHeader(header, value) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
if (arguments.length !== 2) {
throw new TypeError("2 arguments required for setRequestHeader");
}
header = conversions.ByteString(header);
value = conversions.ByteString(value);
if (this.readyState !== XMLHttpRequest.OPENED || properties.send) {
throw new DOMException("The object is in an invalid state.", "InvalidStateError");
}
value = normalizeHeaderValue(value);
if (!tokenRegexp.test(header) || !fieldValueRegexp.test(value)) {
throw new DOMException("The string did not match the expected pattern.", "SyntaxError");
}
const lcHeader = header.toLowerCase();
if (forbiddenRequestHeaders.has(lcHeader) || lcHeader.startsWith("sec-") || lcHeader.startsWith("proxy-")) {
return;
setRequestHeader(header, value) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
if (arguments.length !== 2) {
throw new TypeError("2 arguments required for setRequestHeader");
}
header = conversions.ByteString(header);
value = conversions.ByteString(value);
if (this.readyState !== XMLHttpRequest.OPENED || properties.send) {
throw new DOMException("The object is in an invalid state.", "InvalidStateError");
}
value = normalizeHeaderValue(value);
if (!tokenRegexp.test(header) || !fieldValueRegexp.test(value)) {
throw new DOMException("The string did not match the expected pattern.", "SyntaxError");
}
const lcHeader = header.toLowerCase();
if (forbiddenRequestHeaders.has(lcHeader) || lcHeader.startsWith("sec-") || lcHeader.startsWith("proxy-")) {
return;
}
open(method, uri, asynchronous, user, password) {
if (!this._ownerDocument) {
throw new DOMException("The object is in an invalid state.", "InvalidStateError");
}
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
const argumentCount = arguments.length;
if (argumentCount < 2) {
throw new TypeError("Not enough arguments (expected at least 2)");
}
method = conversions.ByteString(method);
uri = conversions.USVString(uri);
if (user) {
user = conversions.USVString(user);
}
if (password) {
password = conversions.USVString(password);
}
if (!tokenRegexp.test(method)) {
throw new DOMException("The string did not match the expected pattern.", "SyntaxError");
}
const upperCaseMethod = method.toUpperCase();
if (forbiddenRequestMethods.has(upperCaseMethod)) {
throw new DOMException("The operation is insecure.", "SecurityError");
}
getResponseHeader(header) {
const properties = this[xhrSymbols.properties];
const { readyState } = this;
if (readyState === XMLHttpRequest.UNSENT || readyState === XMLHttpRequest.OPENED) {
return null;
}
const lcHeader = conversions.ByteString(header).toLowerCase();
if (properties.filteredResponseHeaders.find(filtered => lcHeader === filtered.toLowerCase())) {
return null;
}
return getResponseHeader(this, lcHeader);
}
getResponseHeader(header) {
const properties = this[xhrSymbols.properties];
const { readyState } = this;
if (readyState === XMLHttpRequest.UNSENT || readyState === XMLHttpRequest.OPENED) {
return null;
}
const lcHeader = conversions.ByteString(header).toLowerCase();
if (properties.filteredResponseHeaders.find(filtered => lcHeader === filtered.toLowerCase())) {
return null;
}
return getResponseHeader(this, lcHeader);
}
getResponseHeader(header) {
const properties = this[xhrSymbols.properties];
const { readyState } = this;
if (readyState === XMLHttpRequest.UNSENT || readyState === XMLHttpRequest.OPENED) {
return null;
}
const lcHeader = conversions.ByteString(header).toLowerCase();
if (properties.filteredResponseHeaders.find(filtered => lcHeader === filtered.toLowerCase())) {
return null;
}
return getResponseHeader(this, lcHeader);
}
getResponseHeader(header) {
const properties = this[xhrSymbols.properties];
const { readyState } = this;
if (readyState === XMLHttpRequest.UNSENT || readyState === XMLHttpRequest.OPENED) {
return null;
}
const lcHeader = conversions.ByteString(header).toLowerCase();
if (properties.filteredResponseHeaders.find(filtered => lcHeader === filtered.toLowerCase())) {
return null;
}
return getResponseHeader(this, lcHeader);
}
.map(key => [conversions.ByteString(key).toLowerCase(), properties.responseHeaders[key]].join(": "))
.join("\r\n");
.map(key => [conversions.ByteString(key).toLowerCase(), properties.responseHeaders[key]].join(": "))
.join("\r\n");