Skip to content

Commit 60365bf

Browse files
authored
Merge pull request #170 from udayvir-singh/main
fix: formatter for html and special casing of content-type
2 parents e1482ea + 17ab07d commit 60365bf

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use {
8080
show_http_info = true,
8181
show_headers = true,
8282
-- executables or functions for formatting response body [optional]
83-
-- set them to nil if you want to disable them
83+
-- set them to false if you want to disable them
8484
formatters = {
8585
json = "jq",
8686
html = function(body)

lua/rest-nvim/config/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ local config = {
1616
formatters = {
1717
json = "jq",
1818
html = function(body)
19+
if vim.fn.executable("tidy") == 0 then
20+
return body
21+
end
1922
-- stylua: ignore
2023
return vim.fn.system({
2124
"tidy", "-i", "-q",

lua/rest-nvim/request/init.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ local function get_body(bufnr, start_line, stop_line, has_json)
6767
end
6868
end
6969

70-
local is_json, json_body = pcall(vim.fn.json_decode, body)
70+
local is_json, json_body = pcall(vim.json.decode, body)
7171

7272
if is_json then
7373
if has_json then
@@ -280,11 +280,20 @@ M.buf_get_request = function(bufnr, curpos)
280280
headers["host"] = nil
281281
end
282282

283+
local content_type = ""
284+
285+
for key, val in pairs(headers) do
286+
if string.lower(key) == "content-type" then
287+
content_type = val
288+
break
289+
end
290+
end
291+
283292
local body = get_body(
284293
bufnr,
285294
body_start,
286295
end_line,
287-
string.find(headers["content-type"] or "", "application/[^ ]-json")
296+
content_type:find("application/[^ ]*json")
288297
)
289298

290299
if config.get("jump_to_request") then

0 commit comments

Comments
 (0)