How to send output without buffering? I defined my API controller this way:
public class DefaultController : ApiController { [HttpGet] [Route] public HttpResponseMessage Get() { var response = Request.CreateResponse(); response.Content = new PushStreamContent( (output, content, context) => { using (var writer = new StreamWriter(output)) { for (int i = 0; i < 5; i++) { writer.WriteLine("Eh?"); writer.Flush(); Thread.Sleep(2000); } } },"text/plain"); return response; } }
Output appears in the browser all at once, so it looks like it waits start sending it till completion. I defined this attribute:
[AttributeUsage(AttributeTargets.Class,AllowMultiple=false)]classNoBufferAttribute:Attribute,IControllerConfiguration{publicvoidInitialize(HttpControllerSettings controllerSettings,HttpControllerDescriptor controllerDescriptor){ controllerSettings.Services.Replace(typeof(IHostBufferPolicySelector),newBufferPolicy());}classBufferPolicy:IHostBufferPolicySelector{public bool UseBufferedInputStream(object hostContext){returnfalse;}public bool UseBufferedOutputStream(HttpResponseMessage response){returnfalse;}}}
And applied it to controller:
[NoBuffer]publicclassDefaultController:ApiController{...}
It did not help. All the output appears in the browser the same time.