Skip to content

Commit 55faa12

Browse files
committed
use timer phase to control http client
1 parent 6944d74 commit 55faa12

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

lapis/http.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
if ngx then
2-
if ngx.config and ngx.config.is_console then
3-
return require("lapis.nginx.resty_http")
4-
else
5-
return require("lapis.nginx.http")
6-
end
2+
return require("lapis.nginx.http")
73
elseif package.loaded["lapis.running_server"] == "cqueues" then
84
return require("http.compat.socket")
95
else

lapis/http.moon

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
if ngx
2-
if ngx.config and ngx.config.is_console
3-
-- the "location capture" client is not compatible with resty
4-
require "lapis.nginx.resty_http"
5-
else
6-
require "lapis.nginx.http"
2+
require "lapis.nginx.http"
73
elseif package.loaded["lapis.running_server"] == "cqueues"
84
require "http.compat.socket"
95
else

lapis/nginx/http.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ simple = function(req, body)
5959
end
6060
local request
6161
request = function(url, str_body)
62+
local _exp_0 = ngx.get_phase()
63+
if "timer" == _exp_0 then
64+
return require("lapis.nginx.resty_http").request(url, str_body)
65+
end
6266
local ltn12 = require("ltn12")
6367
local config = lapis_config.get()
6468
local start_time

lapis/nginx/http.moon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ simple = (req, body) ->
9393
res.body, res.status, res.header
9494

9595
request = (url, str_body) ->
96+
-- handle phases not compatible with location.capture
97+
-- NOTE: while we are testing resty_http integration we are only exposing in
98+
-- timers. You will need to manually opt into lapis.nginx.resty_http to use
99+
-- it in other phases for now, as you may want the existing behavior of an
100+
-- error to be raised if you're doing http requests in weird places
101+
switch ngx.get_phase!
102+
when "timer"
103+
return require("lapis.nginx.resty_http").request url, str_body
104+
96105
ltn12 = require "ltn12"
97106

98107
config = lapis_config.get!

0 commit comments

Comments
 (0)