Skip to content

Commit

Permalink
fix: add body state handling for payload is too big
Browse files Browse the repository at this point in the history
Closed #98.
  • Loading branch information
jellydn committed Mar 13, 2024
1 parent 50406d4 commit c596962
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local http = require('hurl.http_utils')
local M = {}

local response = {}
local head_state = ''
local is_running = false

-- Looking for vars.env file base on the current file buffer
Expand Down Expand Up @@ -100,7 +101,6 @@ end
local on_output = function(code, data, event)
utils.log_info('hurl: on_output ' .. vim.inspect(code) .. vim.inspect(data))

local head_state
if data[1] == '' then
table.remove(data, 1)
end
Expand All @@ -116,6 +116,14 @@ local on_output = function(code, data, event)
return
end

if head_state == 'body' then
-- Append the data to the body if we are in the body state
utils.log_info('hurl: append data to body' .. vim.inspect(data))
response.body = response.body or ''
response.body = response.body .. table.concat(data, '\n')
return
end

-- TODO: The header parser sometime not working properly, e.g: https://google.com
local status = tonumber(string.match(data[1], '([%w+]%d+)'))
head_state = 'start'
Expand Down Expand Up @@ -164,6 +172,7 @@ local function execute_hurl_cmd(opts, callback)
end

is_running = true
head_state = ''
utils.log_info('hurl: running request')
utils.notify('hurl: running request', vim.log.levels.INFO)

Expand Down

0 comments on commit c596962

Please sign in to comment.