Closed javiercn closed 6 years ago
I've confirmed that the issue is due to the lack of server addresses. It works fine when I added them myself.
Justin made this work in his tests by adding the feature manually.
The server does have a base address property we could use to auto populate the feature, but you'd never get more than one address. That might be enough for these tests.
Nevermind, the middleware should allow the feature to be null and fall back to 443.
Yeah, good point.
It's failing at injection time, so we might just do
app.ServerFeatures.GetFeaure<IServerAddressesFeature>() ?? new NoAddressesFeature()
That way we use the class as a hint to the middleware to make DI work and have the middleware redirect to 443
Does it need a value at all?
Right now I throw if the ServerAddress feature is null https://github.com/aspnet/BasicMiddleware/blob/dev/src/Microsoft.AspNetCore.HttpsPolicy/HttpsRedirectionMiddleware.cs#L40. From feedback, I'll go ahead and change the behavior to not throw if the feature isn't set and return 443.
@Tratcher The value is just for DI to be happy. The problem is we are passing down null and that makes activator utilities blow up. The NoAddressesFeature is a special value to signal the middleware that it neesds to do 443. Or if everything just works with an empty ServerAddressesFeature, just use that.
@jkotalik Ah, good point. I actually didn't dig deep enough, and its just constructor throwing. Nevermind anything I said, just make it work with the null value by assuming 443
@javiercn I was mistaken, this also fails at injection time. I think we will have to do something like:
app.ServerFeatures.GetFeaure<IServerAddressesFeature>() ?? new NoAddressesFeature()
or just add a second constructor to HttpsMiddleware that doesn't take an IServerAddressFeature.
Done 726035e
Apparently there are no server addresses feature on the TestServer and that causes the middleware to blow up.
https://github.com/aspnet/BasicMiddleware/blob/dev/src/Microsoft.AspNetCore.HttpsPolicy/HttpsRedirectionMiddleware.cs#L32
@Tratcher Is there something reasonable we can do here for tests? Like allow configuring the addresses on the test server for tests