Package org.apache.catalina.filters
Class RemoteIpFilter.XForwardedRequest
- java.lang.Object
-
- jakarta.servlet.ServletRequestWrapper
-
- jakarta.servlet.http.HttpServletRequestWrapper
-
- org.apache.catalina.filters.RemoteIpFilter.XForwardedRequest
-
- All Implemented Interfaces:
HttpServletRequest,ServletRequest
- Enclosing class:
- RemoteIpFilter
public static class RemoteIpFilter.XForwardedRequest extends HttpServletRequestWrapper
Wrapper forHttpServletRequestthat allows modification of headers, remote address, scheme, and other properties used by the RemoteIpFilter.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>headersMap of header names to their values.protected java.lang.StringlocalNameThe local name of the server.protected intlocalPortThe local port of the server.protected java.lang.StringremoteAddrThe remote address of the client.protected java.lang.StringremoteHostThe remote host of the client.protected java.lang.StringschemeThe scheme of the request.protected java.lang.StringserverNameThe server name.protected intserverPortThe server port.-
Fields inherited from interface jakarta.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
-
Constructor Summary
Constructors Constructor Description XForwardedRequest(HttpServletRequest request)Create a new XForwardedRequest wrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetDateHeader(java.lang.String name)The default behavior of this method is to return getDateHeader(String name) on the wrapped request object.java.lang.StringgetHeader(java.lang.String name)The default behavior of this method is to return getHeader(String name) on the wrapped request object.protected java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>getHeaderEntry(java.lang.String name)Find the header entry for the given name (case-insensitive).java.util.Enumeration<java.lang.String>getHeaderNames()The default behavior of this method is to return getHeaderNames() on the wrapped request object.java.util.Enumeration<java.lang.String>getHeaders(java.lang.String name)The default behavior of this method is to return getHeaders(String name) on the wrapped request object.intgetIntHeader(java.lang.String name)The default behavior of this method is to return getIntHeader(String name) on the wrapped request object.java.lang.StringgetLocalName()The default behavior of this method is to return getLocalName() on the wrapped request object.intgetLocalPort()The default behavior of this method is to return getLocalPort() on the wrapped request object.java.lang.StringgetRemoteAddr()The default behavior of this method is to return getRemoteAddr() on the wrapped request object.java.lang.StringgetRemoteHost()The default behavior of this method is to return getRemoteHost() on the wrapped request object.java.lang.StringBuffergetRequestURL()The default behavior of this method is to return getRequestURL() on the wrapped request object.java.lang.StringgetScheme()The default behavior of this method is to return getScheme() on the wrapped request object.java.lang.StringgetServerName()The default behavior of this method is to return getServerName() on the wrapped request object.intgetServerPort()The default behavior of this method is to return getServerPort() on the wrapped request object.PushBuildernewPushBuilder()Obtain a builder for generating push requests.voidremoveHeader(java.lang.String name)Remove a header by name.voidsetHeader(java.lang.String name, java.lang.String value)Set a header value.voidsetLocalName(java.lang.String localName)Set the local name.voidsetLocalPort(int localPort)Set the local port.voidsetRemoteAddr(java.lang.String remoteAddr)Set the remote address.voidsetRemoteHost(java.lang.String remoteHost)Set the remote host.voidsetScheme(java.lang.String scheme)Set the scheme.voidsetSecure(boolean secure)Set whether the request is secure.voidsetServerName(java.lang.String serverName)Set the server name.voidsetServerPort(int serverPort)Set the server port.-
Methods inherited from class jakarta.servlet.http.HttpServletRequestWrapper
authenticate, changeSessionId, getAuthType, getContextPath, getCookies, getHttpServletMapping, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getServletPath, getSession, getSession, getTrailerFields, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, upgrade
-
Methods inherited from class jakarta.servlet.ServletRequestWrapper
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getProtocolRequestId, getReader, getRemotePort, getRequest, getRequestDispatcher, getRequestId, getServletConnection, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jakarta.servlet.ServletRequest
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getProtocolRequestId, getReader, getRemotePort, getRequestDispatcher, getRequestId, getServletConnection, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
-
-
-
-
Field Detail
-
headers
protected final java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers
Map of header names to their values.
-
localName
protected java.lang.String localName
The local name of the server.
-
localPort
protected int localPort
The local port of the server.
-
remoteAddr
protected java.lang.String remoteAddr
The remote address of the client.
-
remoteHost
protected java.lang.String remoteHost
The remote host of the client.
-
scheme
protected java.lang.String scheme
The scheme of the request.
-
serverName
protected java.lang.String serverName
The server name.
-
serverPort
protected int serverPort
The server port.
-
-
Constructor Detail
-
XForwardedRequest
public XForwardedRequest(HttpServletRequest request)
Create a new XForwardedRequest wrapper.- Parameters:
request- the request to wrap
-
-
Method Detail
-
getDateHeader
public long getDateHeader(java.lang.String name)
Description copied from class:jakarta.servlet.http.HttpServletRequestWrapperThe default behavior of this method is to return getDateHeader(String name) on the wrapped request object.- Specified by:
getDateHeaderin interfaceHttpServletRequest- Overrides:
getDateHeaderin classHttpServletRequestWrapper- Parameters:
name- aStringspecifying the name of the header- Returns:
- a
longvalue representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the request
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Description copied from class:jakarta.servlet.http.HttpServletRequestWrapperThe default behavior of this method is to return getHeader(String name) on the wrapped request object.- Specified by:
getHeaderin interfaceHttpServletRequest- Overrides:
getHeaderin classHttpServletRequestWrapper- Parameters:
name- aStringspecifying the header name- Returns:
- a
Stringcontaining the value of the requested header, ornullif the request does not have a header of that name
-
getHeaderEntry
protected java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>> getHeaderEntry(java.lang.String name)
Find the header entry for the given name (case-insensitive).- Parameters:
name- the header name to look up- Returns:
- the header entry, or
nullif not found
-
getHeaderNames
public java.util.Enumeration<java.lang.String> getHeaderNames()
Description copied from class:jakarta.servlet.http.HttpServletRequestWrapperThe default behavior of this method is to return getHeaderNames() on the wrapped request object.- Specified by:
getHeaderNamesin interfaceHttpServletRequest- Overrides:
getHeaderNamesin classHttpServletRequestWrapper- Returns:
- an enumeration of all the header names sent with this request; if the request has no headers, an empty
enumeration; if the servlet container does not allow servlets to use this method,
null
-
getHeaders
public java.util.Enumeration<java.lang.String> getHeaders(java.lang.String name)
Description copied from class:jakarta.servlet.http.HttpServletRequestWrapperThe default behavior of this method is to return getHeaders(String name) on the wrapped request object.- Specified by:
getHeadersin interfaceHttpServletRequest- Overrides:
getHeadersin classHttpServletRequestWrapper- Parameters:
name- aStringspecifying the header name- Returns:
- an
Enumerationcontaining the values of the requested header. If the request does not have any headers of that name return an empty enumeration. If the container does not allow access to header information, return null
-
getIntHeader
public int getIntHeader(java.lang.String name)
Description copied from class:jakarta.servlet.http.HttpServletRequestWrapperThe default behavior of this method is to return getIntHeader(String name) on the wrapped request object.- Specified by:
getIntHeaderin interfaceHttpServletRequest- Overrides:
getIntHeaderin classHttpServletRequestWrapper- Parameters:
name- aStringspecifying the name of a request header- Returns:
- an integer expressing the value of the request header or -1 if the request doesn't have a header of this name
-
getLocalName
public java.lang.String getLocalName()
Description copied from class:jakarta.servlet.ServletRequestWrapperThe default behavior of this method is to return getLocalName() on the wrapped request object.- Specified by:
getLocalNamein interfaceServletRequest- Overrides:
getLocalNamein classServletRequestWrapper- Returns:
- a
Stringcontaining the host name of the IP on which the request was received.
-
getLocalPort
public int getLocalPort()
Description copied from class:jakarta.servlet.ServletRequestWrapperThe default behavior of this method is to return getLocalPort() on the wrapped request object.- Specified by:
getLocalPortin interfaceServletRequest- Overrides:
getLocalPortin classServletRequestWrapper- Returns:
- an integer specifying the port number
-
getRemoteAddr
public java.lang.String getRemoteAddr()
Description copied from class:jakarta.servlet.ServletRequestWrapperThe default behavior of this method is to return getRemoteAddr() on the wrapped request object.- Specified by:
getRemoteAddrin interfaceServletRequest- Overrides:
getRemoteAddrin classServletRequestWrapper- Returns:
- a
Stringcontaining the IP address of the client that sent the request
-
getRemoteHost
public java.lang.String getRemoteHost()
Description copied from class:jakarta.servlet.ServletRequestWrapperThe default behavior of this method is to return getRemoteHost() on the wrapped request object.- Specified by:
getRemoteHostin interfaceServletRequest- Overrides:
getRemoteHostin classServletRequestWrapper- Returns:
- a
Stringcontaining the fully qualified name of the client
-
getScheme
public java.lang.String getScheme()
Description copied from class:jakarta.servlet.ServletRequestWrapperThe default behavior of this method is to return getScheme() on the wrapped request object.- Specified by:
getSchemein interfaceServletRequest- Overrides:
getSchemein classServletRequestWrapper- Returns:
- a
Stringcontaining the name of the scheme used to make this request
-
getServerName
public java.lang.String getServerName()
Description copied from class:jakarta.servlet.ServletRequestWrapperThe default behavior of this method is to return getServerName() on the wrapped request object.- Specified by:
getServerNamein interfaceServletRequest- Overrides:
getServerNamein classServletRequestWrapper- Returns:
- a
Stringcontaining the name of the server
-
getServerPort
public int getServerPort()
Description copied from class:jakarta.servlet.ServletRequestWrapperThe default behavior of this method is to return getServerPort() on the wrapped request object.- Specified by:
getServerPortin interfaceServletRequest- Overrides:
getServerPortin classServletRequestWrapper- Returns:
- an integer specifying the port number
-
removeHeader
public void removeHeader(java.lang.String name)
Remove a header by name.- Parameters:
name- the header name to remove
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Set a header value.- Parameters:
name- the header namevalue- the header value
-
setLocalName
public void setLocalName(java.lang.String localName)
Set the local name.- Parameters:
localName- the local name
-
setLocalPort
public void setLocalPort(int localPort)
Set the local port.- Parameters:
localPort- the local port
-
setRemoteAddr
public void setRemoteAddr(java.lang.String remoteAddr)
Set the remote address.- Parameters:
remoteAddr- the remote address
-
setRemoteHost
public void setRemoteHost(java.lang.String remoteHost)
Set the remote host.- Parameters:
remoteHost- the remote host
-
setScheme
public void setScheme(java.lang.String scheme)
Set the scheme.- Parameters:
scheme- the scheme
-
setSecure
public void setSecure(boolean secure)
Set whether the request is secure.- Parameters:
secure- whether the request is secure
-
setServerName
public void setServerName(java.lang.String serverName)
Set the server name.- Parameters:
serverName- the server name
-
setServerPort
public void setServerPort(int serverPort)
Set the server port.- Parameters:
serverPort- the server port
-
getRequestURL
public java.lang.StringBuffer getRequestURL()
Description copied from class:jakarta.servlet.http.HttpServletRequestWrapperThe default behavior of this method is to return getRequestURL() on the wrapped request object.- Specified by:
getRequestURLin interfaceHttpServletRequest- Overrides:
getRequestURLin classHttpServletRequestWrapper- Returns:
- a
StringBufferobject containing the reconstructed URL
-
newPushBuilder
public PushBuilder newPushBuilder()
Description copied from class:jakarta.servlet.http.HttpServletRequestWrapperObtain a builder for generating push requests.PushBuilderdocuments how this request will be used as the basis for a push request. Each call to this method will return a new instance, independent of any previous instance obtained.The default behavior of this method is to return
HttpServletRequest.newPushBuilder()on the wrapped request object.- Specified by:
newPushBuilderin interfaceHttpServletRequest- Overrides:
newPushBuilderin classHttpServletRequestWrapper- Returns:
- A builder that can be used to generate push requests based on this request or
nullif push is not supported. Note that even if a PushBuilder instance is returned, by the time thatPushBuilder.push()is called, it may no longer be valid to push a request and the push request will be ignored.
-
-