Body Rewrite
HTTP:body (offset, size)
Offset and size are optional.
If offset is missing, it will be set as zero.
If size is missing, it will be set as -1 which means the whole HTTP body.
Return string. The HTTP body will be returned.
HTTP:set_body("body_str", offset, size)
Offset and size are optional.
If offset is missing, it will be set as zero.
If size is missing, it will be set as -1 which means the whole http
body.
The body_str is the HTTP body. Now only the string type body is supported.
Return boolean: true/false
.
Example of HTTP replace body
when HTTP_REQUEST {
HTTP:collect()
}
--This function will change "username:test" to "username:Test"
function username_first_char_uppercase(str)
local str1 = str:sub(1, 9)
local str2 = str:sub(10, 10)
str2 = str2:upper()
local str3 = str:sub(11, -1)
return str1..str2..str3
end
when HTTP_DATA_REQUEST {
local body_str = HTTP:body(0, 16)
local body_new = body_str:gsub("username:[A-Za-z][A-Za-z0-9_]+", username_first_char_uppercase)
debug("body old = %s, body new = %s\n", body_str, body_new)
HTTP:set_body(body_new, 0, 16)
}