@@ -46,6 +46,7 @@ type pluginConfiguration struct {
4646 path string
4747 authority string
4848 timeout uint32
49+ poke bool
4950}
5051
5152// newPluginConfiguration creates a pluginConfiguration with default values
@@ -91,6 +92,9 @@ type BlockingConfiguration struct {
9192 Timeout string `json:"timeout"`
9293}
9394
95+ type PokeConfiguration struct {
96+ }
97+
9498type Config struct {
9599 // SablierURL in the format of hostname:port. The scheme is excluded
96100 SablierURL string `json:"sablier_url"`
@@ -105,6 +109,7 @@ type Config struct {
105109 SessionDuration string `json:"session_duration"`
106110 Dynamic * DynamicConfiguration `json:"dynamic"`
107111 Blocking * BlockingConfiguration `json:"blocking"`
112+ Poke * PokeConfiguration `json:"poke"`
108113}
109114
110115func (c Config ) GetPath () string {
@@ -133,6 +138,8 @@ func (c Config) GetPath() string {
133138 return c .getDynamicQuery (path )
134139 } else if c .Blocking != nil {
135140 return c .getBlockingQuery (path )
141+ } else if c .Poke != nil {
142+ return c .getPokeQuery (path )
136143 }
137144 return "no strategy configured"
138145}
@@ -183,6 +190,12 @@ func (c Config) getBlockingQuery(path url.URL) string {
183190 return path .String ()
184191}
185192
193+ func (c Config ) getPokeQuery (path url.URL ) string {
194+ path .Path = "/api/strategies/poke"
195+
196+ return path .String ()
197+ }
198+
186199func parsePluginConfiguration (data []byte ) (pluginConfiguration , error ) {
187200 pluginConf := newPluginConfiguration ()
188201 if len (data ) == 0 {
@@ -196,11 +209,20 @@ func parsePluginConfiguration(data []byte) (pluginConfiguration, error) {
196209 return pluginConf , err
197210 }
198211
199- if c .Blocking == nil && c .Dynamic == nil {
200- return pluginConf , fmt .Errorf ("you must specify one strategy (dynamic or blocking)" )
212+ strategyCount := 0
213+ if c .Blocking != nil {
214+ strategyCount ++
201215 }
202-
203- if c .Blocking != nil && c .Dynamic != nil {
216+ if c .Dynamic != nil {
217+ strategyCount ++
218+ }
219+ if c .Poke != nil {
220+ strategyCount ++
221+ }
222+ if strategyCount == 0 {
223+ return pluginConf , fmt .Errorf ("you must specify one strategy (dynamic, blocking or poke)" )
224+ }
225+ if strategyCount > 1 {
204226 return pluginConf , fmt .Errorf ("you must specify only one strategy" )
205227 }
206228
@@ -232,6 +254,7 @@ func parsePluginConfiguration(data []byte) (pluginConfiguration, error) {
232254 }
233255
234256 pluginConf .path = c .GetPath ()
257+ pluginConf .poke = c .Poke != nil
235258
236259 return pluginConf , nil
237260}
@@ -250,6 +273,7 @@ func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
250273 headers : headers ,
251274 cluster : ctx .configuration .cluster ,
252275 timeout : ctx .configuration .timeout ,
276+ poke : ctx .configuration .poke ,
253277 }
254278}
255279
@@ -261,6 +285,7 @@ type httpOnDemand struct {
261285 headers [][2 ]string
262286 cluster string
263287 timeout uint32
288+ poke bool
264289}
265290
266291// Override types.DefaultHttpContext.
@@ -276,6 +301,9 @@ func (ctx *httpOnDemand) OnHttpRequestHeaders(numHeaders int, endOfStream bool)
276301
277302 proxywasm .LogInfof ("http call dispatched to %s" , ctx .cluster )
278303
304+ if ctx .poke {
305+ return types .ActionContinue
306+ }
279307 return types .ActionPause
280308}
281309
0 commit comments