Skip to content

Commit

Permalink
fix: Better URI compliance policy
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Apr 22, 2024
1 parent 8020d97 commit d3de045
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uniresolver.web;

import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;

@Component
public class WebUniResolverWebServerFactoryCustomizer implements WebServerFactoryCustomizer<JettyServletWebServerFactory> {

@Override
public void customize(JettyServletWebServerFactory factory) {
factory.addServerCustomizers(this::customizeUriCompliance);
}

private void customizeUriCompliance(Server server) {
for (Connector connector : server.getConnectors()) {
connector.getConnectionFactories().stream()
.filter(factory -> factory instanceof HttpConnectionFactory)
.forEach(factory -> {
HttpConfiguration httpConfig = ((HttpConnectionFactory) factory).getHttpConfiguration();
httpConfig.setUriCompliance(UriCompliance.UNSAFE);
});
}
}
}

0 comments on commit d3de045

Please sign in to comment.