All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jetty.server.HostHeaderCustomizer Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
// 
// ========================================================================
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// 
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// 
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// 
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// 
package org.eclipse.jetty.server;

import java.util.Objects;
import javax.servlet.http.HttpServletRequest;

/**
 *  Customizes requests that lack the {@code Host} header (for example, HTTP 1.0 requests).
 *  

* In case of HTTP 1.0 requests that lack the {@code Host} header, the application may issue * a redirect, and the {@code Location} header is usually constructed from the {@code Host} * header; if the {@code Host} header is missing, the server may query the connector for its * IP address in order to construct the {@code Location} header, and thus leak to clients * internal IP addresses. *

* This {@link HttpConfiguration.Customizer} is configured with a {@code serverName} and * optionally a {@code serverPort}. * If the {@code Host} header is absent, the configured {@code serverName} will be set on * the request so that {@link HttpServletRequest#getServerName()} will return that value, * and likewise for {@code serverPort} and {@link HttpServletRequest#getServerPort()}. * * @deprecated The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported. */ @Deprecated(since = "2021-05-27") public class HostHeaderCustomizer implements HttpConfiguration.Customizer { private final String serverName; private final int serverPort; /** * @param serverName the {@code serverName} to set on the request (the {@code serverPort} will not be set) */ public HostHeaderCustomizer(String serverName) { this(serverName, 0); } /** * @param serverName the {@code serverName} to set on the request * @param serverPort the {@code serverPort} to set on the request */ public HostHeaderCustomizer(String serverName, int serverPort) { this.serverName = Objects.requireNonNull(serverName); this.serverPort = serverPort; } @Override public void customize(Connector connector, HttpConfiguration channelConfig, Request request) { if (request.getHeader("Host") == null) // TODO set the field as well? request.setAuthority(serverName, serverPort); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy