Esempio n. 1
0
File: fsm.go Progetto: kapalhq/envoy
func downstreamFn(chain ChainSpec, ctx context.ContextSpec) handleStateFn {
	mods := chain.GetModules()
	pin := chain.GetCursor()
	for i := pin; i >= 0; i-- {
		resp, err := mods[i].ProcessResponse(ctx)
		if resp != nil {
			//log.Printf("Module: %s writing response ...", mods[i].GetId())
			ctx.SetHttpResponse(resp)
		}
		if err != nil {
			ctx.SetError(err)
		}
	}
	return finishedFn
}
Esempio n. 2
0
File: fsm.go Progetto: kapalhq/envoy
func upstreamFn(chain ChainSpec, ctx context.ContextSpec) handleStateFn {
	mods := chain.GetModules()
	for i, mod := range mods {
		resp, err := mod.ProcessRequest(ctx)
		chain.SetCursor(i)
		if resp != nil {
			//log.Printf("Module: %s writing response ...", mods[i].GetId())
			ctx.SetHttpResponse(resp)
			return downstreamFn
		}
		if err != nil {
			//log.Printf("Module: %s found error ...", mods[i].GetId())
			ctx.SetError(err)
			return errorFoundFn
		}
	}
	log.Printf("Error. At least one module must to respond")
	ctx.SetError(errors.FromStatus(http.StatusNoContent))
	return errorFoundFn
}