public TxContext(TxCallbacks callbacks) { this.callbacks = callbacks; requestBodyConsumer = new MockDataConsumer(); if (callbacks.OnRequestData != null) requestBodyConsumer.OnDataAction = _ => callbacks.OnRequestData(); if (callbacks.OnRequestDataEnd != null) requestBodyConsumer.OnEndAction = () => callbacks.OnRequestDataEnd(); }
public void Drive(TxCallbacks callbacks, bool keepAlive) { var tx = context.CreateTransaction(); tx.OnRequest(req.Head, keepAlive); if (callbacks.PostOnRequest != null) callbacks.PostOnRequest(); if (req.Body != null) req.Body.Each(data => { tx.OnRequestData(new ArraySegment<byte>(data), null); if (callbacks.PostOnRequestData != null) callbacks.PostOnRequestData(); }); tx.OnRequestEnd(); if (callbacks.PostOnRequestEnd != null) callbacks.PostOnRequestEnd(); }
Tuple<TxCallbacks, List<List<Action>>> CreateCallbacks() { var callins = new List<List<Action>>(); for (int i = 0; i < 6; i++) callins.Add(new List<Action>()); var callbacks = new TxCallbacks() { OnRequest = () => callins[0].ForEach(a => a()), PostOnRequest = () => callins[1].ForEach(a => a()), OnRequestData = () => callins[2].ForEach(a => a()), PostOnRequestData = () => callins[3].ForEach(a => a()), OnRequestDataEnd = () => callins[4].ForEach(a => a()), PostOnRequestEnd = () => callins[5].ForEach(a => a()) }; return Tuple.Create(callbacks, callins); }