added userAgentStartsWith method to HttpUtil

This commit is contained in:
Sebastian Sdorra
2014-03-16 11:45:43 +01:00
parent 9db7284f27
commit d0c94963ee
2 changed files with 41 additions and 0 deletions

View File

@@ -53,6 +53,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -79,6 +80,9 @@ public final class HttpUtil
*/
public static final String HEADER_SCM_CLIENT = "X-SCM-Client";
/** Field description */
public static final String HEADER_USERAGENT = "User-Agent";
/** authentication header */
public static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
@@ -522,6 +526,26 @@ public final class HttpUtil
STATUS_UNAUTHORIZED_MESSAGE);
}
/**
* Returns true if the User-Agent header of the current request starts with
* the given string.
*
*
* @param request http request
* @param userAgent string to test against the header
*
* @return true if the header starts with the given string
*
* @since 1.37
*/
public static boolean userAgentStartsWith(HttpServletRequest request,
String userAgent)
{
return Strings.nullToEmpty(request.getHeader(HEADER_USERAGENT)).toLowerCase(
Locale.ENGLISH).startsWith(
Strings.nullToEmpty(userAgent).toLowerCase(Locale.ENGLISH));
}
//~--- get methods ----------------------------------------------------------
/**