Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lua/rest-nvim/curl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ local function create_error_handler(opts)
end
end

local function parse_headers(headers)
local parsed = {}
for _, header in ipairs(headers) do
if header ~= "" then
local key, value = header:match("([^:]+):%s*(.*)")
if key then
parsed[key] = value or ""
end
end
end
return parsed
end

-- get_or_create_buf checks if there is already a buffer with the rest run results
-- and if the buffer does not exists, then create a new one
M.get_or_create_buf = function()
Expand Down Expand Up @@ -103,6 +116,8 @@ local function create_callback(curl_cmd, opts)
return
end
local res_bufnr = M.get_or_create_buf()
local header_lines = res.headers
res.headers = parse_headers(res.headers)
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+)")
Expand Down Expand Up @@ -154,9 +169,9 @@ local function create_callback(curl_cmd, opts)
vim.api.nvim_buf_set_lines(
res_bufnr,
line_count + 1,
line_count + 1 + #res.headers,
line_count + 1 + #header_lines,
false,
res.headers
header_lines
)
end

Expand Down