Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sweep Rules] Improve variable naming in lua/hurl/main.lua #121

Closed
wants to merge 8 commits into from
15 changes: 8 additions & 7 deletions lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local http = require('hurl.http_utils')
local M = {}

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

-- Looking for vars.env file base on the current file buffer
Expand Down Expand Up @@ -116,7 +116,7 @@ local on_output = function(code, data, event)
return
end

if head_state == 'body' then
if response_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 ''
Expand All @@ -126,7 +126,7 @@ local on_output = function(code, data, event)

-- 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'
response_state = 'start'
if status then
response.status = status
response.headers = { status = data[1] }
Expand All @@ -136,21 +136,22 @@ local on_output = function(code, data, event)
for i = 2, #data do
local line = data[i]
if line == '' or line == nil then
head_state = 'body'
response_state = 'body'
elseif head_state == 'start' then
local key, value = string.match(line, '([%w-]+):%s*(.+)')
local key, value = string.match(line, '([%w-]+):%s*(.+)') or line, ''
if key and value then
response.headers[key] = value
response.headers_str = response.headers_str .. line .. '\r\n'
end
elseif head_state == 'body' then
response.body = response.body or ''
response.body = response.body .. line
response.body = response.body ..
line
end
end
response.raw = data

utils.log_info('hurl: response status ' .. response.status)
utils.log_info('hurl: response status ' .. response.status'))
utils.log_info('hurl: response headers ' .. vim.inspect(response.headers))
if response.body then
utils.log_info('hurl: response body ' .. response.body)
Expand Down
Loading