mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 19:15:52 +01:00
user agents are not longer set to be browsers by default
This commit is contained in:
@@ -56,10 +56,26 @@ public final class UserAgent
|
||||
*/
|
||||
private UserAgent(String name, boolean browser,
|
||||
Charset basicAuthenticationCharset)
|
||||
{
|
||||
this(name, browser, basicAuthenticationCharset, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new user agent
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param browser
|
||||
* @param basicAuthenticationCharset
|
||||
*/
|
||||
private UserAgent(String name, boolean browser,
|
||||
Charset basicAuthenticationCharset,
|
||||
boolean scmClient)
|
||||
{
|
||||
this.name = checkNotNull(name);
|
||||
this.browser = browser;
|
||||
this.basicAuthenticationCharset = checkNotNull(basicAuthenticationCharset);
|
||||
this.scmClient = scmClient;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -159,6 +175,10 @@ public final class UserAgent
|
||||
return browser;
|
||||
}
|
||||
|
||||
public boolean isScmClient() {
|
||||
return scmClient;
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -212,6 +232,21 @@ public final class UserAgent
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to {@code true} if the {@link UserAgent} is an scm client.
|
||||
*
|
||||
*
|
||||
* @param scmClient {@code true} for an scm client
|
||||
*
|
||||
* @return {@code this}
|
||||
*/
|
||||
public Builder scmClient(boolean scmClient)
|
||||
{
|
||||
this.scmClient = scmClient;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the {@link UserAgent}.
|
||||
*
|
||||
@@ -220,7 +255,7 @@ public final class UserAgent
|
||||
*/
|
||||
public UserAgent build()
|
||||
{
|
||||
return new UserAgent(name, browser, basicAuthenticationCharset);
|
||||
return new UserAgent(name, browser, basicAuthenticationCharset, scmClient);
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
@@ -229,7 +264,10 @@ public final class UserAgent
|
||||
private final String name;
|
||||
|
||||
/** indicator for browsers */
|
||||
private boolean browser = true;
|
||||
private boolean browser = false;
|
||||
|
||||
/** indicator for browsers */
|
||||
private boolean scmClient = false;
|
||||
|
||||
/** basic authentication charset */
|
||||
private Charset basicAuthenticationCharset = Charsets.ISO_8859_1;
|
||||
@@ -244,6 +282,9 @@ public final class UserAgent
|
||||
/** indicator for browsers */
|
||||
private final boolean browser;
|
||||
|
||||
/** indicator for scm clients (e.g. git, hg, svn) */
|
||||
private final boolean scmClient;
|
||||
|
||||
/** name of UserAgent */
|
||||
private final String name;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class UserAgentParserTest
|
||||
UserAgent ua = parser.parse(UA_1);
|
||||
|
||||
assertEquals(Charsets.ISO_8859_1, ua.getBasicAuthenticationCharset());
|
||||
assertTrue(ua.isBrowser());
|
||||
assertFalse(ua.isBrowser());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,7 @@ public class GitUserAgentProvider implements UserAgentProvider {
|
||||
@VisibleForTesting
|
||||
static final UserAgent JGIT = UserAgent.builder("JGit")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
@@ -54,6 +55,7 @@ public class GitUserAgentProvider implements UserAgentProvider {
|
||||
@VisibleForTesting
|
||||
static final UserAgent GIT = UserAgent.builder("Git")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
@@ -62,6 +64,7 @@ public class GitUserAgentProvider implements UserAgentProvider {
|
||||
@VisibleForTesting
|
||||
static final UserAgent GIT_LFS = UserAgent.builder("Git Lfs")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
@@ -70,6 +73,7 @@ public class GitUserAgentProvider implements UserAgentProvider {
|
||||
@VisibleForTesting
|
||||
static final UserAgent MSYSGIT = UserAgent.builder("msysGit")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class HgUserAgentProvider implements UserAgentProvider
|
||||
/** mercurial seems to use system encoding */
|
||||
@VisibleForTesting
|
||||
static UserAgent HG = UserAgent.builder("Mercurial").browser(
|
||||
false).basicAuthenticationCharset(
|
||||
false).scmClient(true).basicAuthenticationCharset(
|
||||
Charset.defaultCharset()).build();
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -49,13 +49,13 @@ public final class SvnUserAgentProvider implements UserAgentProvider
|
||||
/** TortoiseSVN */
|
||||
@VisibleForTesting
|
||||
static final UserAgent TORTOISE_SVN =
|
||||
UserAgent.builder("TortoiseSVN").browser(false)
|
||||
UserAgent.builder("TortoiseSVN").browser(false).scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8).build();
|
||||
|
||||
/** Subversion cli client */
|
||||
@VisibleForTesting
|
||||
static final UserAgent SVN =
|
||||
UserAgent.builder("Subversion").browser(false)
|
||||
UserAgent.builder("Subversion").browser(false).scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8).build();
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -43,28 +43,28 @@ public class BrowserUserAgentProvider implements UserAgentProvider
|
||||
@VisibleForTesting
|
||||
static final UserAgent CHROME = UserAgent.builder(
|
||||
"Chrome").basicAuthenticationCharset(
|
||||
Charsets.UTF_8).build();
|
||||
Charsets.UTF_8).browser(true).build();
|
||||
|
||||
/** Field description */
|
||||
private static final String CHROME_PATTERN = "chrome";
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting
|
||||
static final UserAgent FIREFOX = UserAgent.builder("Firefox").build();
|
||||
static final UserAgent FIREFOX = UserAgent.builder("Firefox").browser(true).build();
|
||||
|
||||
/** Field description */
|
||||
private static final String FIREFOX_PATTERN = "firefox";
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting
|
||||
static final UserAgent MSIE = UserAgent.builder("Internet Explorer").build();
|
||||
static final UserAgent MSIE = UserAgent.builder("Internet Explorer").browser(true).build();
|
||||
|
||||
/** Field description */
|
||||
private static final String MSIE_PATTERN = "msie";
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting // todo check charset
|
||||
static final UserAgent SAFARI = UserAgent.builder("Safari").build();
|
||||
static final UserAgent SAFARI = UserAgent.builder("Safari").browser(true).build();
|
||||
|
||||
/** Field description */
|
||||
private static final String OPERA_PATTERN = "opera";
|
||||
@@ -76,7 +76,7 @@ public class BrowserUserAgentProvider implements UserAgentProvider
|
||||
@VisibleForTesting // todo check charset
|
||||
static final UserAgent OPERA = UserAgent.builder(
|
||||
"Opera").basicAuthenticationCharset(
|
||||
Charsets.UTF_8).build();
|
||||
Charsets.UTF_8).browser(true).build();
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user