0
votes

I just found out that "RequestFeatures" is a thing in ASP.net Core, news to me.. Anyways..

I have created a middleware that needs to alter the response body and the headers provided with the response.

Im used to do this by alterntiv it directly on the HttpContext context-object provided as an argument to the Invoke-method.. however I read somewhere that context.Features is the way to go due to optimizations and what not.. (is this true?, I get that its alot easiter to test the Features, than to "mock" an entire HttpContext which has been historically a painful thing to do..) So I created my own implementation of the HttpResponseFeature and registred it in my Invoke method using:

        httpContext.Features.Set<IHttpResponseFeature>
        (
            //Registering my own HttpResponseFeature that takes an argument..
            new MyHttpResponseFeature(httpResponseMessage)
        );

However, the OnCompleted or the OnStarting-methods never runs. I have added a few breakpoints to validate this, but the breakpoints are never hit. Am I missing something?

1
You can see this thread may helpful.Yinqiu

1 Answers

0
votes

Turns out that the FeatureCollection/RequestFeatures is a "new" thing if your building your very own custom HTTP server ontop of ASP.net Core. An article that covers this fairly well is this one: https://reynders.co/use-iserver-from-aspnet-core-to-create-your-own-web-server/