Skip to content

Commit

Permalink
fix: remove unnecessary edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus-Bertell committed Nov 23, 2023
1 parent e326b56 commit 042d6d2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
3 changes: 1 addition & 2 deletions lua/rest-nvim/curl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions lua/rest-nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions lua/rest-nvim/request/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions lua/rest-nvim/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 042d6d2

Please sign in to comment.