DataScript: avi.utils.base64_decode

DataScript

Function avi.utils.base64_decode( string )
Description DataScripts can encode and decode arbitrary data with base64. This can be used for modification of data sent over the wire, or for inspection and security use cases.
Events HTTP_REQ
HTTP_RESP
Parameter string is the string to be decoded.
Returns The decoded string
Related avi.utils.base64_encode()
Example The following example grabs the HTTP basic auth username and adds it as a user ID tag within Avi Vantage, which can be used for log search, persistence, or access control.

if string.beginswith(avi.http.get_header("Authorization"), "Basic ") then
  auth = string.sub(avi.http.get_header("Authorization"), 7)
  decoded = avi.utils.base64_decode(auth)
  username = string.sub(decoded, 0, string.find(decoded, ":") - 1)
  avi.http.set_userid(username)
end