mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 11:38:07 +01:00
Add HttpServletRequestUtil
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user