mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Add "deleteHttpHeader"
This commit is contained in:
@@ -322,6 +322,16 @@ function setHttpHeader(payload, name, value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteHttpHeader(payload, name) {
|
||||||
|
let header = httpHeader(payload, name);
|
||||||
|
|
||||||
|
if (header) {
|
||||||
|
return Buffer.concat([payload.slice(0, header.start), payload.slice(header.end+1, payload.length)])
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
function httpBody(payload) {
|
function httpBody(payload) {
|
||||||
return payload.slice(payload.indexOf("\r\n\r\n") + 4, payload.length);
|
return payload.slice(payload.indexOf("\r\n\r\n") + 4, payload.length);
|
||||||
}
|
}
|
||||||
@@ -395,6 +405,7 @@ module.exports = {
|
|||||||
setHttpStatus: setHttpStatus,
|
setHttpStatus: setHttpStatus,
|
||||||
httpHeader: httpHeader,
|
httpHeader: httpHeader,
|
||||||
setHttpHeader: setHttpHeader,
|
setHttpHeader: setHttpHeader,
|
||||||
|
deleteHttpHeader: deleteHttpHeader,
|
||||||
httpBody: httpBody,
|
httpBody: httpBody,
|
||||||
setHttpBody: setHttpBody,
|
setHttpBody: setHttpBody,
|
||||||
httpBodyParam: httpBodyParam,
|
httpBodyParam: httpBodyParam,
|
||||||
@@ -410,7 +421,7 @@ module.exports = {
|
|||||||
// =========== Tests ==============
|
// =========== Tests ==============
|
||||||
|
|
||||||
function testRunner(){
|
function testRunner(){
|
||||||
["init", "parseMessage", "httpMethod", "httpPath", "setHttpHeader", "httpPathParam", "httpHeader", "httpBody", "setHttpBody", "httpBodyParam", "httpCookie", "setHttpCookie", "httpHeaders"].forEach(function(t){
|
["init", "parseMessage", "httpMethod", "httpPath", "setHttpHeader", "deleteHttpHeader", "httpPathParam", "httpHeader", "httpBody", "setHttpBody", "httpBodyParam", "httpCookie", "setHttpCookie", "httpHeaders"].forEach(function(t){
|
||||||
console.log(`====== Start ${t} =======`)
|
console.log(`====== Start ${t} =======`)
|
||||||
eval(`TEST_${t}()`)
|
eval(`TEST_${t}()`)
|
||||||
console.log(`====== End ${t} =======`)
|
console.log(`====== End ${t} =======`)
|
||||||
@@ -642,6 +653,18 @@ function TEST_setHttpHeader() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TEST_deleteHttpHeader() {
|
||||||
|
const examplePayload = "GET / HTTP/1.1\r\nUser-Agent: Node\r\nContent-Length: 5\r\n\r\nhello";
|
||||||
|
|
||||||
|
// Adding new header
|
||||||
|
let expected = `GET / HTTP/1.1\r\nContent-Length: 5\r\n\r\nhello`;
|
||||||
|
let p = Buffer.from(examplePayload);
|
||||||
|
p = deleteHttpHeader(p, "User-Agent", "test");
|
||||||
|
if (p != expected) {
|
||||||
|
console.error(`setHeader failed, expected delete header 'User-Agent' header: ${p}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function TEST_httpBody() {
|
function TEST_httpBody() {
|
||||||
const examplePayload = "GET / HTTP/1.1\r\nUser-Agent: Node\r\nContent-Length: 5\r\n\r\nhello";
|
const examplePayload = "GET / HTTP/1.1\r\nUser-Agent: Node\r\nContent-Length: 5\r\n\r\nhello";
|
||||||
let body = httpBody(Buffer.from(examplePayload));
|
let body = httpBody(Buffer.from(examplePayload));
|
||||||
|
|||||||
Reference in New Issue
Block a user