diff --git a/lua/rest-nvim/init.lua b/lua/rest-nvim/init.lua index 2d5c280d..fe94261d 100644 --- a/lua/rest-nvim/init.lua +++ b/lua/rest-nvim/init.lua @@ -83,6 +83,7 @@ local function load_external_payload(fileimport_string) end end + -- @param headers table HTTP headers -- @param payload table of the form { external = bool, filename_tpl= path, body_tpl = string } -- with body_tpl an array of lines @@ -100,7 +101,7 @@ local function splice_body(headers, payload) else lines = payload.body_tpl end - local content_type = headers[utils.key(headers, "content-type")] or "" + local content_type = headers[utils.key(headers,"content-type")] or "" local has_json = content_type:find("application/[^ ]*json") local body = "" @@ -152,8 +153,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) end diff --git a/lua/rest-nvim/request/init.lua b/lua/rest-nvim/request/init.lua index 3ec7d258..957fc6a7 100644 --- a/lua/rest-nvim/request/init.lua +++ b/lua/rest-nvim/request/init.lua @@ -21,9 +21,10 @@ local function get_importfile_name(bufnr, start_line, stop_line) local fileimport_inlined 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_inlined = string.sub(fileimport_line[1], 2, 2) ~= '@' fileimport_string = string.gsub(fileimport_line[1], "<@?", "", 1):gsub("^%s+", ""):gsub("%s+$", "") return fileimport_inlined, fileimport_string + end return nil end @@ -41,7 +42,7 @@ local function get_body(bufnr, start_line, stop_line) local inline, importfile = get_importfile_name(bufnr, start_line, stop_line) local lines -- an array of strings if importfile ~= nil then - return { external = true, inline = inline, filename_tpl = importfile } + return { external = true; inline = inline; filename_tpl = importfile } else lines = vim.api.nvim_buf_get_lines(bufnr, start_line, stop_line, false) end @@ -62,7 +63,7 @@ local function get_body(bufnr, start_line, stop_line) end end - return { external = false, inline = false, body_tpl = lines2 } + return { external = false; inline = false; body_tpl = lines2 } end local function get_response_script(bufnr, start_line, stop_line) @@ -284,9 +285,9 @@ M.buf_get_request = function(bufnr, curpos) local curl_args, body_start = get_curl_args(bufnr, headers_end, end_line) - local host = headers[utils.key(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 + headers[utils.key(headers,"host")] = nil local body = get_body(bufnr, body_start, end_line) @@ -301,17 +302,17 @@ M.buf_get_request = function(bufnr, curpos) end local req = { - method = parsed_url.method, - url = parsed_url.url, - http_version = parsed_url.http_version, - headers = headers, - raw = curl_args, - body = body, - bufnr = bufnr, - start_line = start_line, - end_line = end_line, - script_str = script_str, - } + method = parsed_url.method, + url = parsed_url.url, + http_version = parsed_url.http_version, + headers = headers, + raw = curl_args, + body = body, + bufnr = bufnr, + start_line = start_line, + end_line = end_line, + script_str = script_str, + } return true, req end @@ -392,7 +393,7 @@ M.highlight = function(bufnr, start_line, end_line) higroup, { start_line - 1, 0 }, { end_line - 1, end_column }, - { regtype = "c", inclusive = false } + { regtype = "c"; inclusive = false } ) vim.defer_fn(function()