6

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.

alexbt
  • 16,415
  • 6
  • 78
  • 87
Jan Zyka
  • 17,460
  • 16
  • 70
  • 118

1 Answers1

13

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);
                        }
                    }
                }
            });
        }
    };

}
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • Ha, I gave up when reached the Connectors and didn't go the downcast way and further! Thank you very much – Jan Zyka Feb 05 '15 at 12:55