/** * Like {@link #parse}, but never fails and returns the primary agent {@code unknown/0.0.0} if no valid primary * agent can be parsed. */ public static UserAgent tryParse(String userAgent) { return parseInternal(Strings.nullToEmpty(userAgent), true /* lenient */); }
/** * Parses the given string into a {@link UserAgent} or throws an {@link IllegalArgumentException} if no correctly * formatted primary user agent can be found. Incorrectly formatted informational agents are omitted. * <p> * Valid user agent strings loosely follow RFC 7230 (https://tools.ietf.org/html/rfc7230#section-3.2.6). */ public static UserAgent parse(String userAgent) { Preconditions.checkNotNull(userAgent, "userAgent must not be null"); return parseInternal(userAgent, false /* strict */); }