function read_response()

in example/plugins/lua-api/modsecurity/ats-luajit-modsecurity.lua [145:211]


function read_response()
  
  local txn = ts.ctx["mst"]

  if(txn == nil) then
    ts.error("no transaction object")
    return 0
  end

  
  local hdrs = ts.server_response.get_headers()
  for k, v in pairs(hdrs) do
    msc.msc_add_response_header(txn, k, v)
  end
  msc.msc_process_response_headers(txn, ts.server_response.get_status(), "HTTP/"..ts.server_response.get_version())
  msc.msc_process_response_body(txn)
  ts.debug("done with processing response")

  
  local iv = ffi.new("ModSecurityIntervention")
  iv.status = 200
  iv.log = nil
  iv.url = nil
  iv.disruptive = 0
  local iv_res = msc.msc_intervention(txn, iv)
  ts.debug("done with intervention ".. iv_res .. ' with status ' .. iv.status )

  if(iv.log ~= nil) then
    ts.debug("Intervention log: " .. ffi.string(iv.log))
    C.free(iv.log)
  end

  
  ts.ctx['url'] = ''
  if(iv.url ~= nil) then
    ts.ctx['url'] = ffi.string(iv.url)
    C.free(iv.url)
  end

  
  ts.ctx['status'] = nil
  if (iv.status ~= 200) then
    ts.ctx['status'] = iv.status
  end

  
  if(ts.ctx['url'] ~= '' or ts.ctx['status'] ~= nil) then
    ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response)
  end

  
  if(ts.ctx['status'] ~= nil) then
    ts.ctx["mst"] = nil
    msc.msc_process_logging(txn)
    msc.msc_transaction_cleanup(txn)
    ts.debug("done with cleaning up context and return error response")
    return -1
  end

  
  ts.ctx["mst"] = nil
  msc.msc_process_logging(txn)
  msc.msc_transaction_cleanup(txn)
  ts.debug("done with cleaning up context")

  return 0
end