Add HttpServletRequestUtil

This commit is contained in:
Chris Eager
2024-01-31 14:05:22 -06:00
committed by Chris Eager
parent fb39af67e5
commit c838df90ef
6 changed files with 144 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.util;
import javax.servlet.http.HttpServletRequest;
public class HttpServletRequestUtil {
/**
* Returns the remote address of the request, removing bracket ("[…]") host notation from IPv6 addresses present in
* some implementations, notably {@link org.eclipse.jetty.server.HttpChannel}.
*/
public static String getRemoteAddress(final HttpServletRequest request) {
final String remoteAddr = request.getRemoteAddr();
if (remoteAddr.startsWith("[")) {
return remoteAddr.substring(1, remoteAddr.length() - 1);
}
return remoteAddr;
}
}