Skip to content

Commit 997fe12

Browse files
PinpongTpPinpongTongpat
authored andcommitted
add Host request-header support
1 parent d902996 commit 997fe12

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lua/rest-nvim/request/init.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ local function get_importfile_name(bufnr, start_line, stop_line)
2020
local fileimport_line
2121
fileimport_line = vim.api.nvim_buf_get_lines(bufnr, import_line - 1, import_line, false)
2222
fileimport_string = string.gsub(fileimport_line[1], "<", "", 1)
23-
:gsub("^%s+", "")
24-
:gsub("%s+$", "")
23+
:gsub("^%s+", "")
24+
:gsub("%s+$", "")
2525
-- local fileimport_path = path:new(fileimport_string)
2626
-- if fileimport_path:is_absolute() then
2727
if path:new(fileimport_string):is_absolute() then
@@ -78,6 +78,7 @@ local function get_body(bufnr, start_line, stop_line)
7878

7979
return body
8080
end
81+
8182
-- is_request_line checks if the given line is a http request line according to RFC 2616
8283
local function is_request_line(line)
8384
local http_methods = { "GET", "POST", "PUT", "PATCH", "DELETE" }
@@ -193,6 +194,13 @@ M.get_current_request = function()
193194

194195
local headers, body_start = get_headers(bufnr, start_line, end_line)
195196

197+
if headers['host'] ~= nil then
198+
headers['host'] = headers['host']:gsub("%s+", "")
199+
headers['host'] = string.gsub(headers['host'], "%s+", "")
200+
parsed_url.url = headers['host'] .. parsed_url.url
201+
headers['host'] = nil
202+
end
203+
196204
local body = get_body(bufnr, body_start, end_line)
197205

198206
if config.get("jump_to_request") then

tests/get_with_host.http

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GET /api/users?page=5
2+
Host: https://reqres.in

0 commit comments

Comments
 (0)