Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Handle missing/empty proxy header
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Apr 9, 2015
1 parent 7f67211 commit 435fa36
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions zanata-war/src/main/java/org/zanata/util/HttpUtil.java
Expand Up @@ -84,16 +84,20 @@ public static String getUsername(HttpRequest request) {
public static String getClientIp(HttpServletRequest request) {
String ip;

if(StringUtils.isEmpty(PROXY_HEADER)) {
if (StringUtils.isEmpty(PROXY_HEADER)) {
return request.getRemoteAddr();
}

// PROXY_HEADER can be list of ip address
String header = request.getHeader(PROXY_HEADER);
if (header == null) {
return request.getRemoteAddr();
}
String[] ipList =
StringUtils.split(request.getHeader(PROXY_HEADER), ",");
StringUtils.split(header, ",");

if(ipList.length == 1) {
return ipList[0];
if (ipList.length == 0) {
return request.getRemoteAddr();
}

//return last ip address from list if found
Expand Down

0 comments on commit 435fa36

Please sign in to comment.