Skip to content

Commit

Permalink
fix: add ignore http version
Browse files Browse the repository at this point in the history
  • Loading branch information
PinpongTp committed Aug 6, 2022
1 parent 41ae4e5 commit 383af39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lua/rest-nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ rest.run = function(verbose)
Opts = {
method = result.method:lower(),
url = result.url,
-- plenary.curl can't set http protocol version
-- http_version = result.http_version,
headers = result.headers,
raw = config.get("skip_ssl_verification") and { "-k" } or nil,
body = result.body,
Expand All @@ -44,7 +46,7 @@ rest.run = function(verbose)
if not success_req then
vim.api.nvim_err_writeln(
"[rest.nvim] Failed to perform the request.\nMake sure that you have entered the proper URL and the server is running.\n\nTraceback: "
.. req_err
.. req_err
)
end
end
Expand All @@ -65,7 +67,7 @@ rest.last = function()
if not success_req then
vim.api.nvim_err_writeln(
"[rest.nvim] Failed to perform the request.\nMake sure that you have entered the proper URL and the server is running.\n\nTraceback: "
.. req_err
.. req_err
)
end
end
Expand Down
10 changes: 9 additions & 1 deletion lua/rest-nvim/request/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ end
-- parse_url returns a table with the method of the request and the URL
-- @param stmt the request statement, e.g., POST http://localhost:3000/foo
local function parse_url(stmt)
local parsed = utils.split(stmt, " ")
-- remove HTTP
local parsed = utils.split(stmt, " HTTP/")
local http_version = nil
if parsed[2] ~= nil then
http_version = parsed[2]
end
parsed = utils.split(parsed[1], " ")
local http_method = parsed[1]
table.remove(parsed, 1)
local target_url = table.concat(parsed, " ")
Expand All @@ -176,6 +182,7 @@ local function parse_url(stmt)
method = http_method,
-- Encode URL
url = utils.encode_url(utils.replace_vars(target_url)),
http_version = http_version
}
end

Expand Down Expand Up @@ -212,6 +219,7 @@ M.get_current_request = function()
return {
method = parsed_url.method,
url = parsed_url.url,
http_version = parsed_url.http_version,
headers = headers,
body = body,
bufnr = bufnr,
Expand Down
22 changes: 20 additions & 2 deletions tests/get_with_host.http
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
###
# test with Host

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

###
# test with port

GET /api/users?page=5 HTTP/1.1
Host: reqres.in:443

###

GET /api/users?page=5 HTTP/1.1
Host: reqres.in:80

###

GET /api/users?page=5 HTTP/1.1
Host: reqres.in

###

GET /api/users?page=5 HTTP/1.1
Host: https://reqres.in:443

###

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

0 comments on commit 383af39

Please sign in to comment.