VMware Cloud Director HTTP error 431, part 2

Previously I posted an improved NSX LB configuration for use with VMware Cloud Director that can help to restrict unnecessary cookies and avoid errors with excessively large headers.

If instead you are using VMware Avi Load Balancer in front of your Director cells, I want to highlight a recommended DataScript that you can use to accomplish the same result. My colleague Fahad Ladhani posted this in the comments of Tomas Fojta’s blog, but I’m highlighting it here for greater awareness:

-- HTTP_REQUEST
-- get cookies
cookies, count = avi.http.get_cookie_names()
avi.vs.log("cookies_count_before=" .. count)
-- if cookie(s) exists, validate cookie(s) name
if count >= 1 then
  for cookie_num= 1, #cookies do
    -- only keep cookies: JSESSIONID, rstd, vcloud_session_id, vcloud_jwt, sso-preferred, sso_redirect_org, xxxxx.redirectTo and xxxxx.state
    cookie_name = cookies[cookie_num]
    if cookie_name == "JSESSIONID" or  cookie_name == "rstd" or cookie_name == "vcloud_session_id" or cookie_name == "vcloud_jwt" or cookie_name == "sso-preferred" or cookie_name == "sso_redirect_org" then
      avi.vs.log("keep_cookie=" .. cookie_name)
    elseif string.endswith(cookie_name, ".redirectTo") or string.endswith(cookie_name, ".state") then
      avi.vs.log("keep_cookie=" .. cookie_name)
    else
      -- avi.vs.log("delete_cookie=" .. cookie_name)  -- not logging this because log gets truncated
      avi.http.remove_cookie(cookie_name)
    end
  end
end
-- get cookies
cookies, count = avi.http.get_cookie_names()
avi.vs.log("cookies_count_after=" .. count)

Leave a comment