Skip to content

Commit

Permalink
fix: support no response on body
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Dec 12, 2023
1 parent fbd1eab commit ec4262d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ local on_output = function(code, data, event)

utils.log_info('hurl: response status ' .. response.status)
utils.log_info('hurl: response headers ' .. vim.inspect(response.headers))
utils.log_info('hurl: response body ' .. response.body)
if response.body then
utils.log_info('hurl: response body ' .. response.body)
else
-- Fall back to empty string for non-body responses
response.body = ''
end
end

--- Call hurl command
Expand Down Expand Up @@ -207,13 +212,16 @@ local function execute_hurl_cmd(opts, callback)
return
end

local container = require('hurl.' .. _HURL_GLOBAL_CONFIG.mode)
local content_type = response.headers['content-type']
or response.headers['Content-Type']
or ''
or 'unknown'

utils.log_info('Detected content type: ' .. content_type)
if response.headers['content-length'] == '0' then
vim.notify('hurl: empty response', vim.log.levels.INFO)
end

local container = require('hurl.' .. _HURL_GLOBAL_CONFIG.mode)
if utils.is_json_response(content_type) then
container.show(response, 'json')
else
Expand Down

0 comments on commit ec4262d

Please sign in to comment.