On Wed, Feb 12, 2020 at 10:31 AM Gary Gregory <[email protected]>
wrote:
> Hm, that won't work, now that I've debugged some.
>
> I can see that I need to/should create and set my own FixedPortStrategy(0)
> but that does not work since the port is set after the server is started,
> so I'll need a custom "EphemeralPortStrategy" or "AllPortStrategy" that
> accepts any port, but that's lame. How can I say "I am a SecurePortStrategy
> that only accepts the port this server was resolved from the ephemeral
> port"?
>
My current ugly workaround for which I'd hope for a cleaner
within-HC-solution to support ephemeral ports is:
asyncServerBootstrap
.setTlsStrategy(new BasicServerTlsStrategy(sslContext,
port == 0 ? AllSecurePortStrategy.INSTANCE : new FixedPortStrategy(new
int[] { port })));
and:
// HACK IMO
private static final class AllSecurePortStrategy implements
SecurePortStrategy {
static final AllSecurePortStrategy INSTANCE = new
AllSecurePortStrategy();
@Override
public boolean isSecure(SocketAddress localAddress) {
return true;
}
}
Gary
>
> Gary
>
> On Wed, Feb 12, 2020 at 10:09 AM Gary Gregory <[email protected]>
> wrote:
>
>> Hi All:
>>
>> I am trying to fix tests at work that use the ephemeral port, but:
>>
>> org.apache.hc.core5.http2.impl.nio.bootstrap.H2ServerBootstrap.create()
>>
>> uses by default:
>>
>> new H2ServerTlsStrategy(443, 8443),
>>
>> What do you think about making this:
>>
>> new H2ServerTlsStrategy(0, 443, 8443),
>>
>> ?
>>
>> Gary
>>
>>