Skip to content

Commit b8a1bf8

Browse files
fix(ui): handle when content-type is not provided
1 parent c3ff445 commit b8a1bf8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lua/rest-nvim/ui/result.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local ui = {}
1111
local config = require("rest-nvim.config")
1212
local utils = require("rest-nvim.utils")
1313
local paneui = require("rest-nvim.ui.panes")
14+
local logger = require("rest-nvim.logger")
1415

1516
local function set_lines(buffer, lines)
1617
vim.api.nvim_buf_set_lines(buffer, 0, -1, false, lines)
@@ -65,16 +66,19 @@ local panes = {
6566
-- syntax_highlight(self.bufnr, "http")
6667
local lines = render_request(data.request)
6768
if data.response then
69+
logger.debug(data.response.status)
6870
table.insert(lines, ("%d %s %s"):format(data.response.status.code, data.response.status.version, data.response.status.text))
6971
local content_type = data.response.headers["content-type"]
7072
table.insert(lines, "")
7173
table.insert(lines, "#+RES")
7274
local body = vim.split(data.response.body, "\n")
73-
local res_type = content_type[1]:match(".*/([^;]+)")
74-
if res_type == "octet_stream" then
75-
body = { "Binary answer" }
76-
elseif config.response.hooks.format then
77-
body = utils.gq_lines(body, res_type)
75+
if content_type then
76+
local res_type = content_type[1]:match(".*/([^;]+)")
77+
if res_type == "octet_stream" then
78+
body = { "Binary answer" }
79+
elseif config.response.hooks.format then
80+
body = utils.gq_lines(body, res_type)
81+
end
7882
end
7983
vim.list_extend(lines, body)
8084
table.insert(lines, "#+END")
@@ -94,10 +98,12 @@ local panes = {
9498
end
9599
syntax_highlight(self.bufnr, "jproperties")
96100
local lines = {}
101+
logger.debug(data.response.headers)
97102
local headers = vim.iter(data.response.headers):totable()
98103
table.sort(headers, function(b, a) return a[1] > b[1] end)
104+
logger.debug(headers)
99105
for _, header in ipairs(headers) do
100-
if header[1] == "set-cookie" then
106+
if header[1] ~= "set-cookie" then
101107
vim.list_extend(lines, vim.iter(header[2]):map(function (value)
102108
return header[1] .. ": " .. value
103109
end):totable())

0 commit comments

Comments
 (0)