Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing HttpConfiguration of Jetty with Spring Boot

I'm using spring boot (1.2.1 as of now) and I need to increase the default 8k request header size limit which lives in HttpConfiguration class in Jetty. Looking into JettyEmbeddedServletContainerFactory which I can get hold of via EmbeddedServletContainerCustomizer but can't see the way how to change that.

I did have a look on the JettyServerCustomizer as well - I understand I can get hold of the jetty Server via that but again - no way how to change the HttpConfiguration here.

Any tips will be much appreciated.

like image 484
Jan Zyka Avatar asked Feb 05 '15 08:02

Jan Zyka


1 Answers

You can use a JettyServerCustomizer to reconfigure the HttpConfiguration but it's buried a little bit in Jetty's configuration model:

@Bean
public EmbeddedServletContainerCustomizer customizer() {
    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof JettyEmbeddedServletContainerFactory) {
                customizeJetty((JettyEmbeddedServletContainerFactory) container);
            }
        }

        private void customizeJetty(JettyEmbeddedServletContainerFactory jetty) {
            jetty.addServerCustomizers(new JettyServerCustomizer() {

                @Override
                public void customize(Server server) {
                    for (Connector connector : server.getConnectors()) {
                        if (connector instanceof ServerConnector) {
                            HttpConnectionFactory connectionFactory = ((ServerConnector) connector)
                                    .getConnectionFactory(HttpConnectionFactory.class);
                            connectionFactory.getHttpConfiguration()
                                    .setRequestHeaderSize(16 * 1024);
                        }
                    }
                }
            });
        }
    };

}
like image 186
Andy Wilkinson Avatar answered Sep 24 '22 19:09

Andy Wilkinson