Skip to content

Commit 383af39

Browse files
committed
fix: add ignore http version
1 parent 41ae4e5 commit 383af39

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

lua/rest-nvim/init.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ rest.run = function(verbose)
2222
Opts = {
2323
method = result.method:lower(),
2424
url = result.url,
25+
-- plenary.curl can't set http protocol version
26+
-- http_version = result.http_version,
2527
headers = result.headers,
2628
raw = config.get("skip_ssl_verification") and { "-k" } or nil,
2729
body = result.body,
@@ -44,7 +46,7 @@ rest.run = function(verbose)
4446
if not success_req then
4547
vim.api.nvim_err_writeln(
4648
"[rest.nvim] Failed to perform the request.\nMake sure that you have entered the proper URL and the server is running.\n\nTraceback: "
47-
.. req_err
49+
.. req_err
4850
)
4951
end
5052
end
@@ -65,7 +67,7 @@ rest.last = function()
6567
if not success_req then
6668
vim.api.nvim_err_writeln(
6769
"[rest.nvim] Failed to perform the request.\nMake sure that you have entered the proper URL and the server is running.\n\nTraceback: "
68-
.. req_err
70+
.. req_err
6971
)
7072
end
7173
end

lua/rest-nvim/request/init.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ end
167167
-- parse_url returns a table with the method of the request and the URL
168168
-- @param stmt the request statement, e.g., POST http://localhost:3000/foo
169169
local function parse_url(stmt)
170-
local parsed = utils.split(stmt, " ")
170+
-- remove HTTP
171+
local parsed = utils.split(stmt, " HTTP/")
172+
local http_version = nil
173+
if parsed[2] ~= nil then
174+
http_version = parsed[2]
175+
end
176+
parsed = utils.split(parsed[1], " ")
171177
local http_method = parsed[1]
172178
table.remove(parsed, 1)
173179
local target_url = table.concat(parsed, " ")
@@ -176,6 +182,7 @@ local function parse_url(stmt)
176182
method = http_method,
177183
-- Encode URL
178184
url = utils.encode_url(utils.replace_vars(target_url)),
185+
http_version = http_version
179186
}
180187
end
181188

@@ -212,6 +219,7 @@ M.get_current_request = function()
212219
return {
213220
method = parsed_url.method,
214221
url = parsed_url.url,
222+
http_version = parsed_url.http_version,
215223
headers = headers,
216224
body = body,
217225
bufnr = bufnr,

tests/get_with_host.http

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
###
2-
# test with Host
32

43
GET /api/users?page=5
54
Host: https://reqres.in
65

76
###
8-
# test with port
7+
8+
GET /api/users?page=5 HTTP/1.1
9+
Host: reqres.in:443
10+
11+
###
12+
13+
GET /api/users?page=5 HTTP/1.1
14+
Host: reqres.in:80
15+
16+
###
17+
18+
GET /api/users?page=5 HTTP/1.1
19+
Host: reqres.in
20+
21+
###
22+
23+
GET /api/users?page=5 HTTP/1.1
24+
Host: https://reqres.in:443
25+
26+
###
927

1028
GET /api/users?page=5
1129
Host: https://reqres.in:443

0 commit comments

Comments
 (0)