Merge 128295961426896e75bdd3647cbcdf2491b1e757 into dcc28438ff55b5b4f60fe8fbb057ed67e0038d5a

This commit is contained in:
sevzero 2018-05-23 13:21:38 +00:00 committed by GitHub
commit 07832c3e9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 0 deletions

View File

@ -150,6 +150,7 @@ const Categories = [
ops: [ ops: [
"HTTP request", "HTTP request",
"Strip HTTP headers", "Strip HTTP headers",
"Dechunk HTTP response",
"Parse User Agent", "Parse User Agent",
"Parse IP range", "Parse IP range",
"Parse IPv6 address", "Parse IPv6 address",

View File

@ -1846,6 +1846,13 @@ const OperationConfig = {
outputType: "string", outputType: "string",
args: [] args: []
}, },
"Dechunk HTTP response": {
module: "HTTP",
description: "Parses a HTTP response transferred using transfer-encoding:chunked",
inputType: "string",
outputType: "string",
args: []
},
"Parse User Agent": { "Parse User Agent": {
module: "HTTP", module: "HTTP",
description: "Attempts to identify and categorise information contained in a user-agent string.", description: "Attempts to identify and categorise information contained in a user-agent string.",

View File

@ -16,6 +16,7 @@ let OpModules = typeof self === "undefined" ? {} : self.OpModules || {};
OpModules.HTTP = { OpModules.HTTP = {
"HTTP request": HTTP.runHTTPRequest, "HTTP request": HTTP.runHTTPRequest,
"Strip HTTP headers": HTTP.runStripHeaders, "Strip HTTP headers": HTTP.runStripHeaders,
"Dechunk HTTP response": HTTP.runDechunk,
"Parse User Agent": HTTP.runParseUserAgent, "Parse User Agent": HTTP.runParseUserAgent,
}; };

View File

@ -37,6 +37,28 @@ const HTTP = {
return (headerEnd < 2) ? input : input.slice(headerEnd, input.length); return (headerEnd < 2) ? input : input.slice(headerEnd, input.length);
}, },
/**
* Dechunk response operation
*
* @param {string} input
* @param {Object[]} args}
* @returns {string}
*/
runDechunk: function(input, args) {
let chunks = [];
let chunkSizeEnd = input.indexOf("\n") + 1;
let lineEndings = input.charAt(chunkSizeEnd - 2) === "\r" ? "\r\n" : "\n";
let lineEndingsLength = lineEndings.length;
let chunkSize = parseInt(input.slice(0, chunkSizeEnd), 16);
while (!isNaN(chunkSize)) {
chunks.push(input.slice(chunkSizeEnd, chunkSize + chunkSizeEnd));
input = input.slice(chunkSizeEnd + chunkSize + lineEndingsLength);
chunkSizeEnd = input.indexOf(lineEndings) + lineEndingsLength;
chunkSize = parseInt(input.slice(0, chunkSizeEnd), 16);
}
return chunks.join("") + input;
},
/** /**
* Parse User Agent operation. * Parse User Agent operation.