javalin / javalin-ssl

Straightforward SSL Configuration for Javalin!
https://javalin.io/plugins/ssl-helpers
10 stars 1 forks source link

HTTP/2 does not work. #141

Closed MrRedRhino closed 8 months ago

MrRedRhino commented 8 months ago

This plugin does nothing. I'm using version 6.1.0 of Javalin and this plugin.

public static void main(String[] args) {
    SslPlugin sslPlugin = new SslPlugin(sslConfig -> {
        sslConfig.http2 = true;
        sslConfig.secure = false;
        sslConfig.insecurePort = Config.get().apiPort;
    });
    Javalin.create(config -> {
        config.registerPlugin(sslPlugin);

        config.validation.register(LocalDate.class, s -> {
            ...
        });

        config.showJavalinBanner = false;
        config.bundledPlugins.enableCors(c -> c.addRule(CorsPluginConfig.CorsRule::anyHost));
        config.router.apiBuilder(() -> {
            path("api", () -> {
                ...
            });
        });
    }).start();

    SimpleModule module = new SimpleModule();
    module.addSerializer(PlanData.class, new PdfDataSerializer());
    JavalinJackson.Companion.defaultMapper().registerModule(module);
}

This is the console output:

[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO org.eclipse.jetty.server.Server - jetty-11.0.19; built: 2023-12-15T20:54:39.802Z; git: f781e475c8fa9e9c8ce18b1eaa03110d510f905f; jvm 18.0.2.1+1
[main] INFO org.eclipse.jetty.server.session.DefaultSessionIdManager - Session workerName=node0
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@6a6afff2{/,null,AVAILABLE}
[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@3aefe5e5{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:4000}
[main] INFO org.eclipse.jetty.server.Server - Started Server@15eb5ee5{STARTING}[11.0.19,sto=0] @491ms
[main] INFO io.javalin.Javalin - Javalin started in 212ms \o/
[main] INFO io.javalin.Javalin - Listening on http://localhost:4000/
[main] INFO io.javalin.Javalin - You are running Javalin 6.1.0 (released February 17, 2024).

In line 5 it says HTTP/1.1 and my browser shows the same.

I don't want SSL, only http 2. How can I achieve this?

zugazagoitia commented 8 months ago

It is enabled. HTTP/2 works by using the Upgrade header so the first connection will be in HTTP/1.1 but any subsequent requests will use HTTP/2 if your client supports it. If you connect with a browser you'll be able to see on the network tab the protocol. You can see in the line five that both connectors are enabled: {HTTP/1.1, (http/1.1, h2c)} being h2c the HTTP/2 one, which also contains a HTTP/1.