Skip to content

Commit

Permalink
[#2127]remove regex match for remote address resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
flybyray committed May 26, 2017
1 parent 1e80b6e commit 14f73cb
Showing 1 changed file with 9 additions and 10 deletions.
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

0 comments on commit 14f73cb

Please sign in to comment.