Skip to main content

session:request_url_get

Last updated March 2020

Name

session:request_url_get — Get the request URL

Synopsis

session:request_url_get();

Description

Use an ec_httpsrv_session object and this method to return an ec_url_details object. For example code, see “session:request_url_get Example” and “msys.httpsrv.register Example”.

You can access the following fields of the ec_url_details userdata object:

  • url_details.url – Request URL

  • url_details.attrs – Request URL attributes

require("msys.extended.httpsrv")

local function params_handler(session)
  local url_details = session:request_url_get()
  local params = {}

  if url_details.attrs ~= nil then
    local iter = msys.core.dict_iter2(url_details.attrs)
    repeat
      local rc, k, v = msys.core.dict_next(url_details.attrs, iter)
      if rc != 0 then
        params[k] = v
      end
    until rc == 0
    msys.core.dict_iter2_free(url_details.attrs, iter)
  end

  if params.reply == nil or params.reply ~= "true" then
    -- If the reply parameter was missing, return the default HTTP response.
    print("reply not true in " .. url_details.url)
    return msys.httpsrv.DONE
  end

  -- Return all the parameters in a string.
  local sorted_params = {}
  local reply = ""

  for k, v in pairs(params) do
    table.insert(sorted_params, k)
  end
  table.sort(sorted_params)
  for i, k in ipairs(sorted_params) do
    reply = reply .. k .. "=" .. params[k] .. " "
  end
  session:response_status_set_std(200, reply, "text/plain")
end

Enable this function with the statement require("msys.extended.httpsrv");.

See Also

Was this page helpful?