Skip to content

Commit 74bd876

Browse files
committed
better User-Agent
1 parent 6a41b7f commit 74bd876

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/main/java/net/lightbody/bmp/proxy/Main.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.eclipse.jetty.servlet.ServletContextHandler;
1414

1515
import javax.servlet.ServletContextEvent;
16+
import java.io.IOException;
1617
import java.io.InputStream;
1718
import java.util.Properties;
1819
import java.util.logging.ConsoleHandler;
@@ -22,27 +23,19 @@
2223

2324
public class Main {
2425
private static final Log LOG = new Log();
26+
private static String VERSION = null;
2527

2628
public static void main(String[] args) throws Exception {
2729
configureLogging();
2830

29-
String version = "UNKNOWN/DEVELOPMENT";
30-
InputStream is = Main.class.getResourceAsStream("/version.prop");
31-
32-
if (is != null) {
33-
Properties props = new Properties();
34-
props.load(is);
35-
version = props.getProperty("version");
36-
}
37-
3831
final Injector injector = Guice.createInjector(new ConfigModule(args), new JettyModule(), new SitebricksModule() {
3932
@Override
4033
protected void configureSitebricks() {
4134
scan(ProxyResource.class.getPackage());
4235
}
4336
});
4437

45-
LOG.info("Starting BrowserMob Proxy version {}", version);
38+
LOG.info("Starting BrowserMob Proxy version {}", getVersion());
4639

4740
Server server = injector.getInstance(Server.class);
4841
GuiceServletContextListener gscl = new GuiceServletContextListener() {
@@ -59,6 +52,23 @@ protected Injector getInjector() {
5952
server.join();
6053
}
6154

55+
public static String getVersion() throws IOException {
56+
if (VERSION == null) {
57+
String version = "UNKNOWN/DEVELOPMENT";
58+
InputStream is = Main.class.getResourceAsStream("/version.prop");
59+
60+
if (is != null) {
61+
Properties props = new Properties();
62+
props.load(is);
63+
version = props.getProperty("version");
64+
}
65+
66+
VERSION = version;
67+
}
68+
69+
return VERSION;
70+
}
71+
6272
public static void configureLogging() {
6373
Logger logger = Logger.getLogger("");
6474
Handler[] handlers = logger.getHandlers();

src/main/java/net/lightbody/bmp/proxy/http/BrowserMobHttpClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import net.lightbody.bmp.core.har.*;
3333
import net.lightbody.bmp.proxy.BlacklistEntry;
34+
import net.lightbody.bmp.proxy.Main;
3435
import net.lightbody.bmp.proxy.WhitelistEntry;
3536
import net.lightbody.bmp.proxy.util.*;
3637

@@ -740,7 +741,7 @@ private BrowserMobHttpResponse execute(BrowserMobHttpRequest req, int depth) {
740741
try {
741742
// set the User-Agent if it's not already set
742743
if (method.getHeaders("User-Agent").length == 0) {
743-
method.addHeader("User-Agent", "BrowserMob VU/1.0");
744+
method.addHeader("User-Agent", "bmp.lightbody.net/" + Main.getVersion());
744745
}
745746

746747
// was the request mocked out?

0 commit comments

Comments
 (0)