diff options
author | Luke Granger-Brown <git@lukegb.com> | 2012-08-02 23:35:08 +0100 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2012-08-02 21:38:32 -0500 |
commit | 35a3d701a90f685012eb78c3c31a43d3ef596392 (patch) | |
tree | 9fb26cf6ebda7af5dae4e768b63debb3c1427956 /src | |
parent | 8dc52123bfa58fd54b10b5918d06dd2aab765af1 (diff) | |
download | craftbukkit-35a3d701a90f685012eb78c3c31a43d3ef596392.tar craftbukkit-35a3d701a90f685012eb78c3c31a43d3ef596392.tar.gz craftbukkit-35a3d701a90f685012eb78c3c31a43d3ef596392.tar.lz craftbukkit-35a3d701a90f685012eb78c3c31a43d3ef596392.tar.xz craftbukkit-35a3d701a90f685012eb78c3c31a43d3ef596392.zip |
Add trailing / to BukkitDL URLs. Fixes BUKKIT-2015.
Also adds CraftBukkit version number to user agent when communicating with
BukkitDL.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java b/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java index 9ca4c691..c54359d3 100644 --- a/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java +++ b/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java @@ -6,6 +6,7 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.net.URL; +import java.net.URLConnection; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -34,12 +35,18 @@ public class BukkitDLUpdaterService { return null; } + private String getUserAgent() { + return "CraftBukkit/" + BukkitDLUpdaterService.class.getPackage().getImplementationVersion() + "/" + System.getProperty("java.version"); + } + public ArtifactDetails fetchArtifact(String slug) throws UnsupportedEncodingException, IOException { - URL url = new URL("http", host, API_PREFIX_ARTIFACT + slug); + URL url = new URL("http", host, API_PREFIX_ARTIFACT + slug + "/"); InputStreamReader reader = null; try { - reader = new InputStreamReader(url.openStream()); + URLConnection connection = url.openConnection(); + connection.setRequestProperty("User-Agent", getUserAgent()); + reader = new InputStreamReader(connection.getInputStream()); Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, dateDeserializer).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); ArtifactDetails fromJson = gson.fromJson(reader, ArtifactDetails.class); @@ -64,11 +71,13 @@ public class BukkitDLUpdaterService { } public ArtifactDetails.ChannelDetails fetchChannel(String slug) throws UnsupportedEncodingException, IOException { - URL url = new URL("http", host, API_PREFIX_CHANNEL + slug); + URL url = new URL("http", host, API_PREFIX_CHANNEL + slug + "/"); InputStreamReader reader = null; try { - reader = new InputStreamReader(url.openStream()); + URLConnection connection = url.openConnection(); + connection.setRequestProperty("User-Agent", getUserAgent()); + reader = new InputStreamReader(connection.getInputStream()); Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, dateDeserializer).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); ArtifactDetails.ChannelDetails fromJson = gson.fromJson(reader, ArtifactDetails.ChannelDetails.class); |