Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2127]remove regex match for remote address resolution #1153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions framework/src/play/server/PlayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.URLEncoder;
import java.net.*;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -547,14 +546,14 @@ public void copyResponse(ChannelHandlerContext ctx, Request request, Response re
}

static String getRemoteIPAddress(MessageEvent e) {
String fullAddress = ((InetSocketAddress) e.getRemoteAddress()).getAddress().getHostAddress();
if (fullAddress.matches("/[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+[:][0-9]+")) {
fullAddress = fullAddress.substring(1);
fullAddress = fullAddress.substring(0, fullAddress.indexOf(":"));
} else if (fullAddress.matches(".*[%].*")) {
fullAddress = fullAddress.substring(0, fullAddress.indexOf("%"));
}
return fullAddress;
final InetAddress inetAddress = ((InetSocketAddress) e.getRemoteAddress()).getAddress();
final byte[] address = inetAddress.getAddress();
try { //create a new inetaddress only from numeric ( without host and interface information)
return InetAddress.getByAddress(address).getHostAddress();
} catch (UnknownHostException unknownHostException) { //should never happen, else address is wrong
Logger.error(unknownHostException,"Error: resolving numeric address: %s", inetAddress.getHostAddress());
}
return null;
}

public Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyRequest, MessageEvent messageEvent) throws Exception {
Expand Down