Skip to content

Commit bd3cb9c

Browse files
authored
Merge pull request lightbody#576 from jekh/remove-uadetector
Remove uadetector
2 parents e1e97e6 + b89988d commit bd3cb9c

File tree

6 files changed

+6
-105
lines changed

6 files changed

+6
-105
lines changed

browsermob-core/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@
7878
<artifactId>jackson-annotations</artifactId>
7979
</dependency>
8080

81-
<dependency>
82-
<groupId>net.sf.uadetector</groupId>
83-
<artifactId>uadetector-resources</artifactId>
84-
<version>2014.10</version>
85-
</dependency>
86-
8781
<dependency>
8882
<groupId>com.google.guava</groupId>
8983
<artifactId>guava</artifactId>

browsermob-core/src/main/java/net/lightbody/bmp/BrowserMobProxyServer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
import net.lightbody.bmp.proxy.auth.AuthType;
4444
import net.lightbody.bmp.proxy.dns.AdvancedHostResolver;
4545
import net.lightbody.bmp.proxy.dns.DelegatingHostResolver;
46-
import net.lightbody.bmp.util.BrowserMobProxyUtil;
4746
import net.lightbody.bmp.util.BrowserMobHttpUtil;
47+
import net.lightbody.bmp.util.BrowserMobProxyUtil;
4848
import org.littleshoot.proxy.ChainedProxy;
4949
import org.littleshoot.proxy.ChainedProxyAdapter;
5050
import org.littleshoot.proxy.ChainedProxyManager;
@@ -461,9 +461,6 @@ public Har newHar(String initialPageRef) {
461461

462462
@Override
463463
public Har newHar(String initialPageRef, String initialPageTitle) {
464-
// eagerly initialize the User Agent String Parser, since it will be needed for the HAR
465-
BrowserMobProxyUtil.getUserAgentStringParser();
466-
467464
Har oldHar = getHar();
468465

469466
addHarCaptureFilter();

browsermob-core/src/main/java/net/lightbody/bmp/filters/HarCaptureFilter.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import net.lightbody.bmp.core.har.HarCookie;
1818
import net.lightbody.bmp.core.har.HarEntry;
1919
import net.lightbody.bmp.core.har.HarNameValuePair;
20-
import net.lightbody.bmp.core.har.HarNameVersion;
2120
import net.lightbody.bmp.core.har.HarPostData;
2221
import net.lightbody.bmp.core.har.HarPostDataParam;
2322
import net.lightbody.bmp.core.har.HarRequest;
@@ -27,8 +26,6 @@
2726
import net.lightbody.bmp.filters.util.HarCaptureUtil;
2827
import net.lightbody.bmp.proxy.CaptureType;
2928
import net.lightbody.bmp.util.BrowserMobHttpUtil;
30-
import net.lightbody.bmp.util.BrowserMobProxyUtil;
31-
import net.sf.uadetector.ReadableUserAgent;
3229
import org.littleshoot.proxy.impl.ProxyUtils;
3330
import org.slf4j.Logger;
3431
import org.slf4j.LoggerFactory;
@@ -204,7 +201,9 @@ public HttpResponse clientToProxyRequest(HttpObject httpObject) {
204201
harEntry.setResponse(defaultHarResponse);
205202

206203
captureQueryParameters(httpRequest);
207-
captureUserAgent(httpRequest);
204+
// not capturing user agent: in many cases, it doesn't make sense to capture at the HarLog level, since the proxy could be
205+
// serving requests from many different clients with various user agents. clients can turn on the REQUEST_HEADERS capture type
206+
// in order to capture the User-Agent header, if desired.
208207
captureRequestHeaderSize(httpRequest);
209208

210209
if (dataToCapture.contains(CaptureType.REQUEST_COOKIES)) {
@@ -337,23 +336,6 @@ protected void captureQueryParameters(HttpRequest httpRequest) {
337336
}
338337
}
339338

340-
protected void captureUserAgent(HttpRequest httpRequest) {
341-
// save the browser and version if it's not yet been set
342-
if (har.getLog().getBrowser() == null) {
343-
String userAgentHeader = HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.USER_AGENT);
344-
if (userAgentHeader != null && userAgentHeader.length() > 0) {
345-
try {
346-
ReadableUserAgent uai = BrowserMobProxyUtil.getUserAgentStringParser().parse(userAgentHeader);
347-
String browser = uai.getName();
348-
String version = uai.getVersionNumber().toVersionString();
349-
har.getLog().setBrowser(new HarNameVersion(browser, version));
350-
} catch (RuntimeException e) {
351-
log.warn("Failed to parse user agent string", e);
352-
}
353-
}
354-
}
355-
}
356-
357339
protected void captureRequestHeaderSize(HttpRequest httpRequest) {
358340
String requestLine = httpRequest.getMethod().toString() + ' ' + httpRequest.getUri() + ' ' + httpRequest.getProtocolVersion().toString();
359341
// +2 => CRLF after status line, +4 => header/data separation

browsermob-core/src/main/java/net/lightbody/bmp/util/BrowserMobProxyUtil.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import net.lightbody.bmp.core.har.HarLog;
88
import net.lightbody.bmp.core.har.HarPage;
99
import net.lightbody.bmp.mitm.exception.UncheckedIOException;
10-
import net.sf.uadetector.UserAgentStringParser;
11-
import net.sf.uadetector.service.UADetectorServiceFactory;
1210
import org.slf4j.Logger;
1311
import org.slf4j.LoggerFactory;
1412

@@ -32,11 +30,6 @@ public class BrowserMobProxyUtil {
3230
*/
3331
private static final String UNKNOWN_VERSION_STRING = "UNKNOWN-VERSION";
3432

35-
/**
36-
* Singleton User Agent parser.
37-
*/
38-
private static volatile UserAgentStringParser parser;
39-
4033
/**
4134
* Singleton version string loader.
4235
*/
@@ -47,27 +40,6 @@ public String get() {
4740
}
4841
});
4942

50-
private static final Object PARSER_INIT_LOCK = new Object();
51-
52-
/**
53-
* Retrieve the User Agent String Parser. Create the parser if it has not yet been initialized.
54-
*
55-
* @return singleton UserAgentStringParser object
56-
*/
57-
public static UserAgentStringParser getUserAgentStringParser() {
58-
if (parser == null) {
59-
synchronized (PARSER_INIT_LOCK) {
60-
if (parser == null) {
61-
// using resourceModuleParser for now because user-agent-string.info no longer exists. the updating
62-
// parser will get incorrect data and wipe out its entire user agent repository.
63-
parser = UADetectorServiceFactory.getResourceModuleParser();
64-
}
65-
}
66-
}
67-
68-
return parser;
69-
}
70-
7143
/**
7244
* Copies {@link HarEntry} and {@link HarPage} references from the specified har to a new har copy, up to and including
7345
* the specified pageRef. Does not perform a "deep copy", so any subsequent modification to the entries or pages will

browsermob-legacy/src/main/java/net/lightbody/bmp/proxy/http/BrowserMobHttpClient.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.lightbody.bmp.core.har.HarCookie;
88
import net.lightbody.bmp.core.har.HarEntry;
99
import net.lightbody.bmp.core.har.HarNameValuePair;
10-
import net.lightbody.bmp.core.har.HarNameVersion;
1110
import net.lightbody.bmp.core.har.HarPostData;
1211
import net.lightbody.bmp.core.har.HarPostDataParam;
1312
import net.lightbody.bmp.core.har.HarRequest;
@@ -18,11 +17,9 @@
1817
import net.lightbody.bmp.proxy.dns.AdvancedHostResolver;
1918
import net.lightbody.bmp.proxy.jetty.util.MultiMap;
2019
import net.lightbody.bmp.proxy.jetty.util.UrlEncoded;
21-
import net.lightbody.bmp.util.BrowserMobProxyUtil;
2220
import net.lightbody.bmp.proxy.util.CappedByteArrayOutputStream;
2321
import net.lightbody.bmp.proxy.util.ClonedOutputStream;
2422
import net.lightbody.bmp.proxy.util.IOUtils;
25-
import net.sf.uadetector.ReadableUserAgent;
2623
import org.apache.http.Header;
2724
import org.apache.http.HeaderElement;
2825
import org.apache.http.HttpClientConnection;
@@ -220,8 +217,8 @@ public class BrowserMobHttpClient {
220217

221218
/**
222219
* Hostname resolver that wraps a {@link net.lightbody.bmp.proxy.dns.HostResolver}. The wrapped HostResolver can be replaced safely at
223-
* runtime using {@link LegacyHostResolverAdapter#setResolver(net.lightbody.bmp.proxy.dns.HostResolver)}.
224-
* See {@link #setResolver(net.lightbody.bmp.proxy.dns.HostResolver)}.
220+
* runtime using {@link LegacyHostResolverAdapter#setResolver(net.lightbody.bmp.proxy.dns.AdvancedHostResolver)}.
221+
* See {@link #setResolver(net.lightbody.bmp.proxy.dns.AdvancedHostResolver)}.
225222
*/
226223
private final LegacyHostResolverAdapter resolverWrapper = new LegacyHostResolverAdapter(ClientUtil.createDnsJavaWithNativeFallbackResolver());
227224

@@ -636,23 +633,6 @@ private BrowserMobHttpResponse execute(BrowserMobHttpRequest req, int depth) {
636633
HttpRequestBase method = req.getMethod();
637634
String url = method.getURI().toString();
638635

639-
// save the browser and version if it's not yet been set
640-
if (har != null && har.getLog().getBrowser() == null) {
641-
Header[] uaHeaders = method.getHeaders("User-Agent");
642-
if (uaHeaders != null && uaHeaders.length > 0) {
643-
String userAgent = uaHeaders[0].getValue();
644-
try {
645-
// note: this doesn't work for 'Fandango/4.5.1 CFNetwork/548.1.4 Darwin/11.0.0'
646-
ReadableUserAgent uai = BrowserMobProxyUtil.getUserAgentStringParser().parse(userAgent);
647-
String browser = uai.getName();
648-
String version = uai.getVersionNumber().toVersionString();
649-
har.getLog().setBrowser(new HarNameVersion(browser, version));
650-
} catch (RuntimeException e) {
651-
LOG.warn("Failed to parse user agent string", e);
652-
}
653-
}
654-
}
655-
656636
// process any rewrite requests
657637
boolean rewrote = false;
658638
String newUrl = url;
@@ -1155,9 +1135,6 @@ public void abortActiveRequests() {
11551135

11561136
public void setHar(Har har) {
11571137
this.har = har;
1158-
1159-
// eagerly initialize the User Agent String Parser, since it will be needed for the HAR
1160-
BrowserMobProxyUtil.getUserAgentStringParser();
11611138
}
11621139

11631140
public void setHarPageRef(String harPageRef) {

browsermob-legacy/src/test/java/net/lightbody/bmp/proxy/HarTest.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,6 @@ public void testRequestAndResponseSizesAreSet() throws Exception {
8484
assertEquals(13, entry.getResponse().getBodySize());
8585
}
8686

87-
@Test
88-
public void testHarContainsUserAgent() throws IOException, InterruptedException {
89-
proxy.setCaptureHeaders(true);
90-
proxy.newHar("testHarContainsUserAgent");
91-
92-
HttpGet httpGet = new HttpGet(getLocalServerHostnameAndPort() + "/echo");
93-
httpGet.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/31.0");
94-
EntityUtils.consumeQuietly(client.execute(httpGet).getEntity());
95-
96-
Thread.sleep(500);
97-
Har har = proxy.getHar();
98-
assertNotNull("Har is null", har);
99-
HarLog log = har.getLog();
100-
assertNotNull("Log is null", log);
101-
HarNameVersion harNameVersion = log.getBrowser();
102-
assertNotNull("HarNameVersion is null", harNameVersion);
103-
104-
assertEquals("Expected browser to be Firefox", "Firefox", harNameVersion.getName());
105-
assertEquals("Expected browser version to be 31.0", "31.0", harNameVersion.getVersion());
106-
}
107-
10887
@Test
10988
public void testThatProxyCanCaptureBodyInHar() throws IOException, InterruptedException {
11089
proxy.setCaptureContent(true);

0 commit comments

Comments
 (0)