Created
February 12, 2022 05:17
-
-
Save xWTF/1d94282898578c0aec7de25a0412b5af to your computer and use it in GitHub Desktop.
Zabbix web.page.get chunked response preprocessor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright © 2022 xWTF | |
This work is free. You can redistribute it and/or modify it under the | |
terms of the Do What The Fuck You Want To Public License, Version 2, | |
as published by Sam Hocevar. See the COPYING file or http://www.wtfpl.net/ | |
for more details. | |
*/ | |
// Usage: Create a Javascript preprocessor and copy paste function body into it | |
function preprocessor() { | |
value = value.split('\r\n\r\n'); | |
var header = value.splice(0, 1)[0]; | |
value = value.join('\r\n\r\n'); | |
if (header.indexOf('chunked') == -1) { | |
return value; | |
} | |
var result = '', index = 0; | |
while(true) { | |
var i = value.indexOf('\r\n', index); | |
if (i == -1) { | |
break; | |
} | |
var len = parseInt(value.substring(index, index + i), 16); | |
if (len == 0 || isNaN(len)) { | |
break; | |
} | |
index = i + 2; | |
result += value.substring(index, index + len); | |
index += len + 2; | |
}; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment