Skip to content

Commit b44e602

Browse files
committed
feat: be able to use environment variables in headers
1 parent 30f2325 commit b44e602

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lua/rest-nvim/init.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ local function get_body(bufnr, stop_line, query_line, json_body)
8484
)
8585

8686
for _, json_line in ipairs(json_lines) do
87-
if json_line:find('^%s+#') == nil then
87+
if not json_line:find('^%s+#') then
8888
json_string = json_string .. utils.replace_env_vars(json_line)
8989
end
9090
end
@@ -141,17 +141,19 @@ local function get_headers(bufnr, query_line)
141141
header = utils.split(header, ':')
142142
if
143143
header[1]:lower() ~= 'accept'
144-
-- If header key doesn't contains double quotes,
145-
-- so we don't get body keys
146-
and header[1]:find('"') == nil
144+
-- If header key doesn't contains double quotes at the
145+
-- start, so we don't get body keys
146+
and not header[1]:find('^%s+"')
147147
-- If header key doesn't contains hashes,
148148
-- so we don't get commented headers
149-
and header[1]:find('^%s+#') == nil
149+
and not header[1]:find('^%s+#')
150150
-- If header key doesn't contains HTTP methods,
151151
-- so we don't get the http method/url
152152
and not utils.has_value(http_methods, header[1])
153153
then
154-
headers[header[1]:lower()] = header[2]
154+
headers[header[1]:lower()] = utils.replace_env_vars(
155+
header[2]
156+
)
155157
end
156158
end
157159
end
@@ -183,7 +185,7 @@ local function get_accept(bufnr, query_line)
183185
)
184186

185187
for _, accept_data in pairs(accept_line) do
186-
if accept_data:find('^%s+#') == nil then
188+
if not accept_data:find('^%s+#') then
187189
accept = utils.split(accept_data, ':')[2]
188190
end
189191
end

0 commit comments

Comments
 (0)