From c596962d952bef76dd3c34580e54c803069e84ef Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Wed, 13 Mar 2024 22:26:53 +0800 Subject: [PATCH] fix: add body state handling for payload is too big Closed #98. --- lua/hurl/main.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/hurl/main.lua b/lua/hurl/main.lua index 4a33f57..10bdeb6 100644 --- a/lua/hurl/main.lua +++ b/lua/hurl/main.lua @@ -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 @@ -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 @@ -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' @@ -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)