|
| 1 | +/* |
| 2 | + * Copyright (C) 2009-2015 Slava Semushin <slava.semushin@gmail.com> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | + */ |
| 18 | +package ru.mystamps.web.support.spring.boot; |
| 19 | + |
| 20 | +import org.eclipse.jetty.server.Connector; |
| 21 | +import org.eclipse.jetty.server.ForwardedRequestCustomizer; |
| 22 | +import org.eclipse.jetty.server.HttpConfiguration; |
| 23 | +import org.eclipse.jetty.server.HttpConnectionFactory; |
| 24 | +import org.eclipse.jetty.server.Server; |
| 25 | +import org.eclipse.jetty.server.ServerConnector; |
| 26 | + |
| 27 | +import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; |
| 28 | +import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; |
| 29 | +import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; |
| 30 | +import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; |
| 31 | +import org.springframework.context.annotation.Configuration; |
| 32 | + |
| 33 | +@Configuration |
| 34 | +public class JettyServletContainerCustomizer implements EmbeddedServletContainerCustomizer { |
| 35 | + |
| 36 | + private static final JettyServerCustomizer JETTY_CUSTOMIZER = new JettyServerCustomizer() { |
| 37 | + @Override |
| 38 | + public void customize(Server server) { |
| 39 | + for (Connector connector : server.getConnectors()) { |
| 40 | + if (connector instanceof ServerConnector) { |
| 41 | + HttpConnectionFactory connectionFactory = |
| 42 | + connector.getConnectionFactory(HttpConnectionFactory.class); |
| 43 | + if (connectionFactory != null) { |
| 44 | + HttpConfiguration httpConfiguration = |
| 45 | + connectionFactory.getHttpConfiguration(); |
| 46 | + if (httpConfiguration != null) { |
| 47 | + httpConfiguration.setSendServerVersion(false); |
| 48 | + httpConfiguration.addCustomizer(new ForwardedRequestCustomizer()); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + }; |
| 55 | + |
| 56 | + @Override |
| 57 | + public void customize(ConfigurableEmbeddedServletContainer container) { |
| 58 | + if (container instanceof JettyEmbeddedServletContainerFactory) { |
| 59 | + JettyEmbeddedServletContainerFactory jetty = |
| 60 | + (JettyEmbeddedServletContainerFactory)container; |
| 61 | + jetty.addServerCustomizers(JETTY_CUSTOMIZER); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments