Skip to content

Commit c186d3e

Browse files
authored
Merge pull request #255 from eightpigs/fix/headersTBL
Fix: content-type cannot be extracted from headers
2 parents b8d6c0a + 43dc4dc commit c186d3e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lua/rest-nvim/curl/init.lua

+17-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ local function create_error_handler(opts)
5454
end
5555
end
5656

57+
local function parse_headers(headers)
58+
local parsed = {}
59+
for _, header in ipairs(headers) do
60+
if header ~= "" then
61+
local key, value = header:match("([^:]+):%s*(.*)")
62+
if key then
63+
parsed[key] = value or ""
64+
end
65+
end
66+
end
67+
return parsed
68+
end
69+
5770
-- get_or_create_buf checks if there is already a buffer with the rest run results
5871
-- and if the buffer does not exists, then create a new one
5972
M.get_or_create_buf = function()
@@ -103,6 +116,8 @@ local function create_callback(curl_cmd, opts)
103116
return
104117
end
105118
local res_bufnr = M.get_or_create_buf()
119+
local header_lines = res.headers
120+
res.headers = parse_headers(res.headers)
106121
local content_type = res.headers[utils.key(res.headers,'content-type')]
107122
if content_type then
108123
content_type = content_type:match("application/([-a-z]+)") or content_type:match("text/(%l+)")
@@ -154,9 +169,9 @@ local function create_callback(curl_cmd, opts)
154169
vim.api.nvim_buf_set_lines(
155170
res_bufnr,
156171
line_count + 1,
157-
line_count + 1 + #res.headers,
172+
line_count + 1 + #header_lines,
158173
false,
159-
res.headers
174+
header_lines
160175
)
161176
end
162177

0 commit comments

Comments
 (0)