How to control HTTP/2 for a single listener

54 views
Skip to first unread message

Brad Wood

unread,
Jun 3, 2023, 12:58:18 AM6/3/23
to Undertow Dev
If I have more than one HTTPS listener on my server, how can I enable HTTP/2 for one listener, but disable it for another listener.  I can pass an OptionMap of overrides for a single socket when creating a listener, but HTTP/2 is not an Xnio option, it's an Undertow option.   Is it OK to mix both UndertowOptions and XnioOptions in the OptionMap of overrides I provide to my listener?

Thanks!

~Brad

Brad Wood

unread,
Jun 7, 2023, 5:15:59 PM6/7/23
to Undertow Dev
So, after doing some testing, this is what I've found:
  • Setting UndertowOptions.ENABLE_HTTP2 in serverBuilder.setServerOption() appears to be the ONLY way to enable HTTP/2 and it is either enabled or disabled for all listeners on the server
  • Setting  UndertowOptions.ENABLE_HTTP2 in serverBuilder.setSocketOption() has no affect and is ignored for the server
  • Setting  UndertowOptions.ENABLE_HTTP2 in listenerBuilder.setOverrideSocketOptions() has no affect and is ignored for the socket/listener
It would appear that Undertow does not allow me to enable or disable HTTP/2 for a single listener (host:port combination), despite this being possible in other web servers such as Nginx, etc.  Is this a bug?  Oversight?

Brad Wood

unread,
Jun 28, 2023, 2:21:33 PM6/28/23
to Undertow Dev
Any input on this?  Have I found an Undertow bug?

Carter Kozak

unread,
Jun 28, 2023, 2:48:11 PM6/28/23
to undert...@googlegroups.com
I'm not a maintainer, but supporting http/2 on a per-listener basis sounds very reasonable to me. For what it's worth, you can do this today so long as you aren't using the Undertow helper class, and bootstrap the server as described here:

-ck

Brad Wood

unread,
Jun 28, 2023, 2:53:24 PM6/28/23
to Carter Kozak, undert...@googlegroups.com
Thanks for the idea, Carter.  Would I need to use a separate XNIO worker for each listener in this case?

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 



--
You received this message because you are subscribed to the Google Groups "Undertow Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to undertow-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/undertow-dev/5f9ec8b1-3953-4b78-b0b1-082613ab9cea%40app.fastmail.com.
For more options, visit https://groups.google.com/d/optout.

Carter Kozak

unread,
Jun 28, 2023, 3:17:41 PM6/28/23
to Brad Wood, undert...@googlegroups.com
Nope, one shared worker for all listeners should do the trick. I’d recommend using the docs as a loose guide, and reimplementing the pieces of Undertow.java that you need, that way you avoid unintentional side-effects.

-ck

On Jun 28, 2023, at 14:53, Brad Wood <bdw...@gmail.com> wrote:



Brad Wood

unread,
Jun 28, 2023, 3:19:51 PM6/28/23
to Carter Kozak, undert...@googlegroups.com
Right, I'm just trying to figure out exactly what would be different between your suggested approach and using the builder.  I mean, I understand I'd be bypassing the builder.  But how exactly would I be building Undertow differently to allow for a per-listener HTTP/2 setting?  If I just copy what the builder code in Undertow.java is doing, then I'd just end up with the same result as the builder, right?

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 

Carter Kozak

unread,
Jun 28, 2023, 3:34:58 PM6/28/23
to Brad Wood, undert...@googlegroups.com
Sorry, I should have specified :-]
You'd make a change such that this boolean is controlled by a piece of data from the ListenerConfig (rather than something that applies across the full breadth of the server, see how 'useProxyProtocol' works): https://github.com/undertow-io/undertow/blob/1340347d9ad0b7d92f2dac8b29d4d5999eec4b0c/core/src/main/java/io/undertow/Undertow.java#L180C29-L180C2

-ck

Brad Wood

unread,
Jun 28, 2023, 3:37:11 PM6/28/23
to Carter Kozak, undert...@googlegroups.com
That makes perfect sense.  Thanks again.  Perhaps I'll enter a ticket for Undertow to control this via a socket or listener-specific setting, but in the meantime this seems like a reasonable workaround.

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


Message has been deleted

Brad Wood

unread,
Sep 1, 2023, 2:18:55 PM9/1/23
to Undertow Dev
Reply all
Reply to author
Forward
0 new messages