Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// These aren't supposed to have any body
return false;
}
// header content is a string, and distinction between 0 and no information is crucial
if ('0' === res.headers['content-length']) {
// We know that the body is empty (unfortunately, this check does not cover chunked encoding)
return false;
}
// console.log(res);
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(method => {
const name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = (url, data, fn) => {
const req = request(method, url);
if ('function' == typeof data) (fn = data), (data = null);
if (data) {
if (method === 'GET' || method === 'HEAD') {
let {
method,
endpoint,
query,
body
} = request;
// パラメータを検証
if (method == null || endpoint == null) {
return connection.error('rest', 'request format is invalid');
}
method = method.toLowerCase();
if (methods.indexOf(method) == -1) {
return connection.error('rest', '"method" parameter is invalid');
}
// endpointを整形
if (endpoint == '') {
endpoint = '/';
}
else if (endpoint != '/' && endpoint[endpoint.length - 1] == '/') {
endpoint = endpoint.substr(0, endpoint.length - 1);
}
// 対象Routeのモジュールを取得
let routeFunc;
let params = [];
try {
this._connectOverride = {'*': connectOverride};
} else if ('object' === typeof connectOverride) {
this._connectOverride = connectOverride;
} else {
this._connectOverride = undefined;
}
return this;
};
Request.prototype.trustLocalhost = function(toggle) {
this._trustLocalhost = toggle === undefined ? true : toggle;
return this;
};
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(method => {
const name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = (url, data, fn) => {
const req = request(method, url);
if ('function' == typeof data) (fn = data), (data = null);
if (data) {
if (method === 'GET' || method === 'HEAD') {
function supports(method) {
return ~methods.indexOf(method);
}
function supports (method) {
return method &&
typeof method === 'string' &&
methods.indexOf(method.toLowerCase()) !== -1
}