diff --git a/lua/rest-nvim/curl/init.lua b/lua/rest-nvim/curl/init.lua index ebfebb26..6fb760fd 100644 --- a/lua/rest-nvim/curl/init.lua +++ b/lua/rest-nvim/curl/init.lua @@ -117,7 +117,6 @@ local function create_callback(curl_cmd, opts) headers = utils.map(headers, function(value) local _, _, http, status = string.find(value, "^(HTTP.*)%s+(%d+)%s*$") - vim.print(value, http, status) if http and status then return http .. " " .. utils.http_status(tonumber(status)) @@ -132,7 +131,7 @@ local function create_callback(curl_cmd, opts) res.headers = parse_headers(res.headers) - local content_type = utils.get_value(res.headers, "content-type") + local content_type = res.headers[utils.key(res.headers, "content-type")] if content_type then content_type = content_type:match("application/([-a-z]+)") or content_type:match("text/(%l+)") end diff --git a/lua/rest-nvim/init.lua b/lua/rest-nvim/init.lua index d8ccd375..2d5c280d 100644 --- a/lua/rest-nvim/init.lua +++ b/lua/rest-nvim/init.lua @@ -100,7 +100,7 @@ local function splice_body(headers, payload) else lines = payload.body_tpl end - local content_type = utils.get_value(headers, "content-type") or "" + local content_type = headers[utils.key(headers, "content-type")] or "" local has_json = content_type:find("application/[^ ]*json") local body = "" @@ -139,9 +139,8 @@ end rest.run_request = function(req, opts) -- TODO rename result to request local result = req - local curl_raw_args = config.get("skip_ssl_verification") - and vim.list_extend(result.raw, { "-k" }) - or result.raw + local curl_raw_args = config.get("skip_ssl_verification") and vim.list_extend(result.raw, { "-k" }) + or result.raw opts = vim.tbl_deep_extend( "force", -- use value from rightmost map defaultRequestOpts, @@ -153,8 +152,7 @@ rest.run_request = function(req, opts) local spliced_body = nil if not req.body.inline and req.body.filename_tpl then curl_raw_args = vim.tbl_extend("force", curl_raw_args, { - "--data-binary", - "@" .. load_external_payload(req.body.filename_tpl), + "--data-binary", "@" .. load_external_payload(req.body.filename_tpl), }) else spliced_body = splice_body(result.headers, result.body) diff --git a/lua/rest-nvim/request/init.lua b/lua/rest-nvim/request/init.lua index e41125d5..3ec7d258 100644 --- a/lua/rest-nvim/request/init.lua +++ b/lua/rest-nvim/request/init.lua @@ -22,8 +22,7 @@ local function get_importfile_name(bufnr, start_line, stop_line) fileimport_line = vim.api.nvim_buf_get_lines(bufnr, import_line - 1, import_line, false) -- check second char against '@' (meaning "dont inline") fileimport_inlined = string.sub(fileimport_line[1], 2, 2) ~= "@" - fileimport_string = - string.gsub(fileimport_line[1], "<@?", "", 1):gsub("^%s+", ""):gsub("%s+$", "") + fileimport_string = string.gsub(fileimport_line[1], "<@?", "", 1):gsub("^%s+", ""):gsub("%s+$", "") return fileimport_inlined, fileimport_string end return nil @@ -285,7 +284,7 @@ M.buf_get_request = function(bufnr, curpos) local curl_args, body_start = get_curl_args(bufnr, headers_end, end_line) - local host = utils.get_value(headers, "host") or "" + local host = headers[utils.key(headers, "host")] or "" parsed_url.url = host:gsub("%s+", "") .. parsed_url.url headers[utils.key(headers, "host")] = nil diff --git a/lua/rest-nvim/utils/init.lua b/lua/rest-nvim/utils/init.lua index 8cb6b997..94375551 100644 --- a/lua/rest-nvim/utils/init.lua +++ b/lua/rest-nvim/utils/init.lua @@ -317,16 +317,6 @@ M.key = function(tbl, key) return key end ---- Get the table value or nil if not found ---- ---- @param tbl (table) Table to iterate over ---- @param key (string) The key to the value case insensitive ---- ---- @return any -M.get_value = function(tbl, key) - return tbl[M.key(tbl, key)] -end - -- tbl_to_str recursively converts the provided table into a json string -- @param tbl Table to convert into a String -- @param json If the string should use a key:value syntax