Skip to content

Commit f01fb8e

Browse files
fix(parser): set host based on header of strings
1 parent 100626e commit f01fb8e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lua/rest-nvim/parser/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ function M.parse(node, source, ctx)
288288

289289
local headers = parse_headers(req_node, source, ctx)
290290
-- HACK: check if url doesn't have host
291-
if headers["host"] and url[1] == "/" then
292-
url = headers["host"]..url
293-
headers["host"] = nil
291+
if headers["host"] and vim.startswith(url, "/") then
292+
url = "http://" ..headers["host"][1]..url
293+
table.remove(headers["host"], 1)
294294
end
295295
---@type rest.Request
296296
local req = {

spec/api_spec.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,14 @@ GET http://localhost:80
218218
local names = parser.get_request_names(source)
219219
assert.same({"first named request", "second named request"}, names)
220220
end)
221+
it("parse request with host header", function ()
222+
local source = [[
223+
GET /some/path
224+
HOST: localhost:8000
225+
]]
226+
local _, tree = utils.ts_parse_source(source)
227+
local req_node = assert(tree:root():child(0))
228+
local req = assert(parser.parse(req_node, source))
229+
assert.same("http://localhost:8000/some/path", req.url)
230+
end)
221231
end)

0 commit comments

Comments
 (0)