2018-05-21 21:08:24 +02:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-07-09 13:23:59 +02:00
|
|
|
import Operation from "../Operation.mjs";
|
2018-05-21 21:08:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip HTTP headers operation
|
|
|
|
*/
|
|
|
|
class StripHTTPHeaders extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* StripHTTPHeaders constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Strip HTTP headers";
|
|
|
|
this.module = "Default";
|
|
|
|
this.description = "Removes HTTP headers from a request or response by looking for the first instance of a double newline.";
|
2018-08-21 20:07:13 +02:00
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Hypertext_Transfer_Protocol#Message_format";
|
2018-05-21 21:08:24 +02:00
|
|
|
this.inputType = "string";
|
|
|
|
this.outputType = "string";
|
|
|
|
this.args = [];
|
2020-02-25 12:27:03 +01:00
|
|
|
this.checks = {
|
|
|
|
input: {
|
|
|
|
regex: [
|
|
|
|
{
|
|
|
|
match: "^\\s*HTTP(.|\\s)+?(\\r?\\n){2}",
|
|
|
|
flags: "",
|
|
|
|
args: []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2018-05-21 21:08:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
let headerEnd = input.indexOf("\r\n\r\n");
|
|
|
|
headerEnd = (headerEnd < 0) ? input.indexOf("\n\n") + 2 : headerEnd + 4;
|
|
|
|
|
|
|
|
return (headerEnd < 2) ? input : input.slice(headerEnd, input.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default StripHTTPHeaders;
|