From 21360f1d2a2b7c8a7c1dfb2d364ad3de684fcc0f Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 8 Dec 2015 16:18:06 +1100 Subject: [PATCH 01/17] http.request: Add :to_curl method that returns the equivalent request as a curl command line --- http/request.lua | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/http/request.lua b/http/request.lua index e7ea6834..a944aca3 100644 --- a/http/request.lua +++ b/http/request.lua @@ -113,6 +113,90 @@ function request_methods:to_url() return scheme .. "://" .. authority .. path end +local function cmdline_escape(str) + if str:match("[^%w%_%:%/%@%^%.%-]") then + return "'" .. str:gsub("'", "\\'") .. "'" + else + return str + end +end +function request_methods:to_curl() + local cmd = { + "curl"; + "--location-trusted"; + "--post301"; + "--post302"; + "--post303"; + } + local n = 5 + + if self.max_redirects ~= 50 then + cmd[n+1] = "--max-redirs" + cmd[n+2] = string.format("%d", self.max_redirects or -1) + n = n + 2 + end + + if self.expect_100_timeout ~= 1 then + error("NYI") -- the option to change this curl setting isn't in man page + end + + if self.tls and self.tls ~= true then + error("NYI") + end + + local scheme = self.headers:get(":scheme") + -- Unlike the ':tourl' method, curl needs the authority in the URI to be the actual host/port + local authority = http_util.to_authority(self.host, self.port, scheme) + local path = self.headers:get(":path") + cmd[n+1] = scheme .. "://" .. authority .. path + n = n + 1 + + for name, value in self.headers:each() do + if name:sub(1,1) == ":" then + if name == ":authority" then + if value ~= authority then + cmd[n+1] = "-H" + cmd[n+2] = "host: " .. value + n = n + 2 + end + elseif name == ":method" then + if value == "HEAD" then + cmd[n+1] = "-I" + n = n + 1 + elseif (value ~= "GET" or self.body ~= nil) and (value ~= "POST" or self.body == nil) then + cmd[n+1] = "-X" + cmd[n+2] = value + n = n + 2 + end + end + elseif name == "user-agent" then + cmd[n+1] = "-A" + cmd[n+2] = value + n = n + 2 + else + cmd[n+1] = "-H" + cmd[n+2] = name .. ": " .. value + n = n + 2 + end + end + + if self.body then + if type(self.body) == "string" then + cmd[n+1] = "--data-raw" + cmd[n+2] = self.body + n = n + 2 + else + error("NYI") + end + end + + -- escape ready for a command line + for i=1, n do + cmd[i] = cmdline_escape(cmd[i]) + end + return table.concat(cmd, " ", 1, n) +end + function request_methods:new_stream(timeout) -- TODO: pooling local connection = client_connect({ From bf2e5ca37f01b3b6be9e8f3950e3d58d6d3fde54 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 8 Dec 2015 16:38:07 +1100 Subject: [PATCH 02/17] http.request: :to_curl: fix command line escaping --- http/request.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/http/request.lua b/http/request.lua index a944aca3..67757a32 100644 --- a/http/request.lua +++ b/http/request.lua @@ -113,13 +113,6 @@ function request_methods:to_url() return scheme .. "://" .. authority .. path end -local function cmdline_escape(str) - if str:match("[^%w%_%:%/%@%^%.%-]") then - return "'" .. str:gsub("'", "\\'") .. "'" - else - return str - end -end function request_methods:to_curl() local cmd = { "curl"; @@ -192,7 +185,10 @@ function request_methods:to_curl() -- escape ready for a command line for i=1, n do - cmd[i] = cmdline_escape(cmd[i]) + local arg = cmd[i] + if arg:match("[^%w%_%:%/%@%^%.%-]") then + cmd[i] = "'" .. arg:gsub("'", "'\\''") .. "'" + end end return table.concat(cmd, " ", 1, n) end From e66c5f3083090a3d3aa6fcb870b03e3b305c7f86 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 8 Dec 2015 16:38:26 +1100 Subject: [PATCH 03/17] http.request: :to_curl better comments --- http/request.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http/request.lua b/http/request.lua index 67757a32..33184309 100644 --- a/http/request.lua +++ b/http/request.lua @@ -123,7 +123,7 @@ function request_methods:to_curl() } local n = 5 - if self.max_redirects ~= 50 then + if self.max_redirects ~= 50 then -- curl default is 50 cmd[n+1] = "--max-redirs" cmd[n+2] = string.format("%d", self.max_redirects or -1) n = n + 2 @@ -138,7 +138,7 @@ function request_methods:to_curl() end local scheme = self.headers:get(":scheme") - -- Unlike the ':tourl' method, curl needs the authority in the URI to be the actual host/port + -- Unlike the ':to_url' method, curl needs the authority in the URI to be the actual host/port local authority = http_util.to_authority(self.host, self.port, scheme) local path = self.headers:get(":path") cmd[n+1] = scheme .. "://" .. authority .. path From 588e6557b323f83e89a71ec0312d9b48fd834659 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sat, 19 Dec 2015 00:19:34 +1100 Subject: [PATCH 04/17] http/request: Fix NYI. curl gained a flag for setting the expect timeout https://github.com/bagder/curl/commit/b4a39491cacde68c9ed5499db7fcc873976e1879 --- http/request.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/http/request.lua b/http/request.lua index 33184309..7d1d5dd5 100644 --- a/http/request.lua +++ b/http/request.lua @@ -130,7 +130,9 @@ function request_methods:to_curl() end if self.expect_100_timeout ~= 1 then - error("NYI") -- the option to change this curl setting isn't in man page + cmd[n+1] = "--expect100-timeout" + cmd[n+2] = string.format("%d", self.expect_100_timeout) + n = n + 2 end if self.tls and self.tls ~= true then From 60e039d7e0d18de5aab65766b2d6786291501704 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 14:50:42 +1100 Subject: [PATCH 05/17] http.request: Reorder checks in to_curl --- http/request.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/http/request.lua b/http/request.lua index 9d82f4c4..2cae8f81 100644 --- a/http/request.lua +++ b/http/request.lua @@ -137,18 +137,18 @@ function request_methods:to_curl() } local n = 5 - if self.max_redirects ~= 50 then -- curl default is 50 - cmd[n+1] = "--max-redirs" - cmd[n+2] = string.format("%d", self.max_redirects or -1) - n = n + 2 - end - if self.expect_100_timeout ~= 1 then cmd[n+1] = "--expect100-timeout" cmd[n+2] = string.format("%d", self.expect_100_timeout) n = n + 2 end + if self.max_redirects ~= 50 then -- curl default is 50 + cmd[n+1] = "--max-redirs" + cmd[n+2] = string.format("%d", self.max_redirects or -1) + n = n + 2 + end + if self.tls and self.tls ~= true then error("NYI") end From 40d81ca9b833bc7f6086da1aa10cf8b5e1c135b7 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 14:51:36 +1100 Subject: [PATCH 06/17] http.request: :to_curl: add support for post301 and post302 options --- http/request.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/http/request.lua b/http/request.lua index 2cae8f81..a11c9067 100644 --- a/http/request.lua +++ b/http/request.lua @@ -131,11 +131,9 @@ function request_methods:to_curl() local cmd = { "curl"; "--location-trusted"; - "--post301"; - "--post302"; "--post303"; } - local n = 5 + local n = 3 if self.expect_100_timeout ~= 1 then cmd[n+1] = "--expect100-timeout" @@ -149,6 +147,16 @@ function request_methods:to_curl() n = n + 2 end + if self.post301 then + cmd[n+1] = "--post301" + n = n + 1 + end + + if self.post302 then + cmd[n+1] = "--post302" + n = n + 1 + end + if self.tls and self.tls ~= true then error("NYI") end From f264b44048e6c5ce95d2fb47d927d63014c1e3f2 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 14:52:51 +1100 Subject: [PATCH 07/17] http.request: :to_curl: Don't return --post303 --- http/request.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/http/request.lua b/http/request.lua index a11c9067..c8984c95 100644 --- a/http/request.lua +++ b/http/request.lua @@ -131,9 +131,8 @@ function request_methods:to_curl() local cmd = { "curl"; "--location-trusted"; - "--post303"; } - local n = 3 + local n = 2 if self.expect_100_timeout ~= 1 then cmd[n+1] = "--expect100-timeout" From 6b147be9add86665260489085cb4a4109151259f Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 14:52:29 +1100 Subject: [PATCH 08/17] http.request: :to_curl: add support for (maps to --location-trusted) --- http/request.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/http/request.lua b/http/request.lua index c8984c95..db8b5cce 100644 --- a/http/request.lua +++ b/http/request.lua @@ -130,9 +130,8 @@ end function request_methods:to_curl() local cmd = { "curl"; - "--location-trusted"; } - local n = 2 + local n = 1 if self.expect_100_timeout ~= 1 then cmd[n+1] = "--expect100-timeout" @@ -140,6 +139,11 @@ function request_methods:to_curl() n = n + 2 end + if self.follow_redirects then + cmd[n+1] = "--location-trusted" + n = n + 1 + end + if self.max_redirects ~= 50 then -- curl default is 50 cmd[n+1] = "--max-redirs" cmd[n+2] = string.format("%d", self.max_redirects or -1) From 54c0d9d6c55a75e883e852addbc5e65b5cfdc5ca Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 15:06:42 +1100 Subject: [PATCH 09/17] http/request: `:to_curl`: if URL contains a curl-globbable character, pass -g --- http/request.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/http/request.lua b/http/request.lua index db8b5cce..1494acb1 100644 --- a/http/request.lua +++ b/http/request.lua @@ -168,7 +168,13 @@ function request_methods:to_curl() -- Unlike the ':to_url' method, curl needs the authority in the URI to be the actual host/port local authority = http_util.to_authority(self.host, self.port, scheme) local path = self.headers:get(":path") - cmd[n+1] = scheme .. "://" .. authority .. path + local url = scheme .. "://" .. authority .. path + if url:match("[%[%]%{%}]") then + -- Turn off curl URL globbing + cmd[n+1] = "-g" + n = n + 1 + end + cmd[n+1] = url n = n + 1 for name, value in self.headers:each() do From 84bb632956faeda08767b8a8e2f217ec652168d7 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 15:12:17 +1100 Subject: [PATCH 10/17] http/request: `:to_curl`: Validate path is okay for curl --- http/request.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/http/request.lua b/http/request.lua index 1494acb1..7755b513 100644 --- a/http/request.lua +++ b/http/request.lua @@ -168,6 +168,7 @@ function request_methods:to_curl() -- Unlike the ':to_url' method, curl needs the authority in the URI to be the actual host/port local authority = http_util.to_authority(self.host, self.port, scheme) local path = self.headers:get(":path") + assert(path == "" or path:sub(1,1) == "/" or path:sub(1,1) == "?", "invalid path for cURL") local url = scheme .. "://" .. authority .. path if url:match("[%[%]%{%}]") then -- Turn off curl URL globbing From 2926c011d2d228ae2b684eafe7daceb1c3d85117 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 15:18:02 +1100 Subject: [PATCH 11/17] http/request: `:to_curl`: handle `.version` field --- http/request.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/http/request.lua b/http/request.lua index 7755b513..5baa556b 100644 --- a/http/request.lua +++ b/http/request.lua @@ -133,6 +133,19 @@ function request_methods:to_curl() } local n = 1 + if self.version then + if self.version == 1 then + cmd[n+1] = "-0" + elseif self.version == 1.1 then + cmd[n+1] = "--http1.1" + elseif self.version == 2 then + cmd[n+1] = "--http2" + else + error("invalid version") + end + n = n + 1 + end + if self.expect_100_timeout ~= 1 then cmd[n+1] = "--expect100-timeout" cmd[n+2] = string.format("%d", self.expect_100_timeout) From c4df6a4801b0025d44c56535592363e67c912fd3 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 15:22:26 +1100 Subject: [PATCH 12/17] http/request: `:to_curl`: Add `-e ;auto` to command lines reflect that we update referer on redirects --- http/request.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/http/request.lua b/http/request.lua index 5baa556b..69e61073 100644 --- a/http/request.lua +++ b/http/request.lua @@ -154,7 +154,9 @@ function request_methods:to_curl() if self.follow_redirects then cmd[n+1] = "--location-trusted" - n = n + 1 + cmd[n+2] = "-e" + cmd[n+3] = ";auto" + n = n + 3 end if self.max_redirects ~= 50 then -- curl default is 50 @@ -213,6 +215,15 @@ function request_methods:to_curl() cmd[n+1] = "-A" cmd[n+2] = value n = n + 2 + elseif name == "referer" then + cmd[n+1] = "-e" + assert(not value:match("[^;]"), "cannot render referer") + if self.follow_redirects then + cmd[n+2] = value .. ";auto" + else + cmd[n+2] = value + end + n = n + 2 else cmd[n+1] = "-H" cmd[n+2] = name .. ": " .. value From c0da4867fd90cd6812dfe787b3238e4415dc0a66 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 20 Jan 2016 15:30:39 +1100 Subject: [PATCH 13/17] http/request: `:to_curl`: Don't bother setting redirect related options if redirects are disabled --- http/request.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/http/request.lua b/http/request.lua index 69e61073..581d8a8f 100644 --- a/http/request.lua +++ b/http/request.lua @@ -157,22 +157,22 @@ function request_methods:to_curl() cmd[n+2] = "-e" cmd[n+3] = ";auto" n = n + 3 - end - if self.max_redirects ~= 50 then -- curl default is 50 - cmd[n+1] = "--max-redirs" - cmd[n+2] = string.format("%d", self.max_redirects or -1) - n = n + 2 - end + if self.max_redirects ~= 50 then -- curl default is 50 + cmd[n+1] = "--max-redirs" + cmd[n+2] = string.format("%d", self.max_redirects or -1) + n = n + 2 + end - if self.post301 then - cmd[n+1] = "--post301" - n = n + 1 - end + if self.post301 then + cmd[n+1] = "--post301" + n = n + 1 + end - if self.post302 then - cmd[n+1] = "--post302" - n = n + 1 + if self.post302 then + cmd[n+1] = "--post302" + n = n + 1 + end end if self.tls and self.tls ~= true then From d09cd722c95a4db8dea30d02d4517b0738107c63 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 31 Oct 2016 14:36:44 +1100 Subject: [PATCH 14/17] spec/request_spec: Add tests for :to_curl() --- spec/request_spec.lua | 99 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/spec/request_spec.lua b/spec/request_spec.lua index 63315a4a..bda50ac7 100644 --- a/spec/request_spec.lua +++ b/spec/request_spec.lua @@ -157,6 +157,105 @@ describe("http.request module", function() test("https://foo:bar@example.com:1234") assert.has.errors(function() test("https://example.com/path") end) end) + describe(":to_curl() #curl", function() + it("lua-http defaults", function() + local req = request.new_from_uri("http://example.com/") + req.headers:delete "user-agent" -- take variability out of tests + assert.same("curl --location-trusted -e ';auto' --max-redirs 5 http://example.com/", req:to_curl()) + end) + local req_template = request.new_from_uri("http://example.com/") + req_template.headers:delete "user-agent" -- take variability out of tests + req_template.follow_redirects = false -- closer to curl defaults + req_template.max_redirects = 50 + it("curl defaults", function() + local req = req_template:clone() + assert.same("curl http://example.com/", req:to_curl()) + end) + it("http version 1.0", function() + local req = req_template:clone() + req.version = 1 + assert.same("curl -0 http://example.com/", req:to_curl()) + end) + it("http version 1.1", function() + local req = req_template:clone() + req.version = 1.1 + assert.same("curl --http1.1 http://example.com/", req:to_curl()) + end) + it("http version 2", function() + local req = req_template:clone() + req.version = 2 + assert.same("curl --http2 http://example.com/", req:to_curl()) + end) + it("expect_100_timeout flag", function() + local req = req_template:clone() + req.expect_100_timeout = 2 + assert.same("curl --expect100-timeout 2 http://example.com/", req:to_curl()) + end) + it("post301 flag", function() + local req = req_template:clone() + req.follow_redirects = nil + req.post301 = true + assert.same("curl --location-trusted -e ';auto' --post301 http://example.com/", req:to_curl()) + end) + it("post302 flag", function() + local req = req_template:clone() + req.follow_redirects = nil + req.post302 = true + assert.same("curl --location-trusted -e ';auto' --post302 http://example.com/", req:to_curl()) + end) + it("path component", function() + local req = req_template:clone() + req.headers:upsert(":path", "/[complex]&path{component}") + assert.same("curl -g 'http://example.com/[complex]&path{component}'", req:to_curl()) + end) + it("query component", function() + local req = req_template:clone() + req.headers:upsert(":path", "/path?query") + assert.same("curl 'http://example.com/path?query'", req:to_curl()) + end) + it("scheme change", function() + local req = req_template:clone() + req.headers:upsert(":scheme", "https") + assert.same("curl https://example.com:80/ -H 'host: example.com'", req:to_curl()) + end) + it("scheme and port change", function() + local req = req_template:clone() + req.headers:upsert(":scheme", "https") + req.port = 443 + assert.same("curl https://example.com/", req:to_curl()) + end) + it("port change", function() + local req = req_template:clone() + req.port = 443 + assert.same("curl http://example.com:443/ -H 'host: example.com'", req:to_curl()) + end) + it("host change", function() + local req = req_template:clone() + req.headers:upsert(":authority", "foo.com") + assert.same("curl http://example.com/ -H 'host: foo.com'", req:to_curl()) + end) + it("head method", function() + local req = req_template:clone() + req.headers:upsert(":method", "HEAD") + assert.same("curl http://example.com/ -I", req:to_curl()) + end) + it("post method with body", function() + local req = req_template:clone() + req.headers:upsert(":method", "POST") + req.body = "foo" + assert.same("curl http://example.com/ --data-raw foo", req:to_curl()) + end) + it("post method without body", function() + local req = req_template:clone() + req.headers:upsert(":method", "POST") + assert.same("curl http://example.com/ -X POST", req:to_curl()) + end) + it("custom headers", function() + local req = req_template:clone() + req.headers:append("foo", "bar") + assert.same("curl http://example.com/ -H 'foo: bar'", req:to_curl()) + end) + end) it(":set_body sets content-length for string arguments", function() local req = request.new_from_uri("http://example.com") assert.falsy(req.headers:has("content-length")) From 9deed93ee47b715f7af04e2d9468ae8b40d02fba Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 31 Oct 2016 14:42:03 +1100 Subject: [PATCH 15/17] http/request: Fix incorrect assert for validating referer --- http/request.lua | 2 +- spec/request_spec.lua | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/http/request.lua b/http/request.lua index 86b2ad1a..6759bfee 100644 --- a/http/request.lua +++ b/http/request.lua @@ -257,7 +257,7 @@ function request_methods:to_curl() n = n + 2 elseif name == "referer" then cmd[n+1] = "-e" - assert(not value:match("[^;]"), "cannot render referer") + assert(not value:match(";"), "cannot render referer") if self.follow_redirects then cmd[n+2] = value .. ";auto" else diff --git a/spec/request_spec.lua b/spec/request_spec.lua index bda50ac7..1a3d833a 100644 --- a/spec/request_spec.lua +++ b/spec/request_spec.lua @@ -250,6 +250,11 @@ describe("http.request module", function() req.headers:upsert(":method", "POST") assert.same("curl http://example.com/ -X POST", req:to_curl()) end) + it("referer header", function() + local req = req_template:clone() + req.headers:upsert("referer", "foo.com") + assert.same("curl http://example.com/ -e foo.com", req:to_curl()) + end) it("custom headers", function() local req = req_template:clone() req.headers:append("foo", "bar") From 784494026c372756a05dff2a7cdae4c5ac7f42bc Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 31 Oct 2016 14:44:37 +1100 Subject: [PATCH 16/17] spec/request_spec: Add more tests for :to_curl() --- spec/request_spec.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/request_spec.lua b/spec/request_spec.lua index 1a3d833a..b0d8aa3f 100644 --- a/spec/request_spec.lua +++ b/spec/request_spec.lua @@ -250,11 +250,22 @@ describe("http.request module", function() req.headers:upsert(":method", "POST") assert.same("curl http://example.com/ -X POST", req:to_curl()) end) + it("referer header", function() + local req = req_template:clone() + req.headers:upsert("user-agent", "myuseragent") + assert.same("curl http://example.com/ -A myuseragent", req:to_curl()) + end) it("referer header", function() local req = req_template:clone() req.headers:upsert("referer", "foo.com") assert.same("curl http://example.com/ -e foo.com", req:to_curl()) end) + it("referer header when follow_redirects is on", function() + local req = req_template:clone() + req.headers:upsert("referer", "foo.com") + req.follow_redirects = nil + assert.same("curl --location-trusted -e ';auto' http://example.com/ -e 'foo.com;auto'", req:to_curl()) + end) it("custom headers", function() local req = req_template:clone() req.headers:append("foo", "bar") From 953c1cc6b9090b42cb28f25e6f5174bbb54a3d69 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 31 Oct 2016 15:10:39 +1100 Subject: [PATCH 17/17] http/request: Have :to_curl() pay attention to proxies --- http/request.lua | 16 ++++++++++++++++ spec/request_spec.lua | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/http/request.lua b/http/request.lua index 6759bfee..f37a1aac 100644 --- a/http/request.lua +++ b/http/request.lua @@ -186,6 +186,22 @@ function request_methods:to_curl() n = n + 1 end + if self.proxy then + if type(self.proxy) ~= "string" then + error("NYI") + end + cmd[n+1] = "--proxy" + cmd[n+2] = self.proxy + n = n + 2 + elseif not self.proxies then + cmd[n+1] = "--noproxy" + cmd[n+2] = "*" + n = n + 2 + elseif self.proxies ~= default_proxies then + assert(getmetatable(self.proxies) == http_proxies.mt, "proxies property should be a http.proxies object") + error("NYI") + end + if self.expect_100_timeout ~= 1 then cmd[n+1] = "--expect100-timeout" cmd[n+2] = string.format("%d", self.expect_100_timeout) diff --git a/spec/request_spec.lua b/spec/request_spec.lua index b0d8aa3f..8f7456ae 100644 --- a/spec/request_spec.lua +++ b/spec/request_spec.lua @@ -234,6 +234,16 @@ describe("http.request module", function() req.headers:upsert(":authority", "foo.com") assert.same("curl http://example.com/ -H 'host: foo.com'", req:to_curl()) end) + it("proxy", function() + local req = req_template:clone() + req.proxy = "http://foo.com" + assert.same("curl --proxy http://foo.com http://example.com/", req:to_curl()) + end) + it("proxies", function() + local req = req_template:clone() + req.proxies = false + assert.same("curl --noproxy '*' http://example.com/", req:to_curl()) + end) it("head method", function() local req = req_template:clone() req.headers:upsert(":method", "HEAD")