Skip to content

Commit

Permalink
add fake User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
robin4002 committed Jul 4, 2017
1 parent 3069aa2 commit 80a75e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repositories {

group = 'net.minecraftforgefrance'
archivesBaseName = 'installer'
version = '2.3.0'
version = '2.3.1'
targetCompatibility = '1.6'
sourceCompatibility = '1.6'

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/fr/minecraftforgefrance/common/DownloadUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import java.util.zip.GZIPInputStream;

import javax.swing.JOptionPane;

Expand Down Expand Up @@ -53,8 +54,21 @@ public static void readRemoteList(List<FileEntry> files, List<String> dirs)
try
{
URL resourceUrl = new URL(RemoteInfoReader.instance().getSyncUrl());
URLConnection connection = resourceUrl.openConnection();
connection.setRequestProperty("Accept-Encoding", "gzip");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:10.0) Gecko/20100101 Firefox/55.0");

JdomParser parser = new JdomParser();
JsonRootNode data = parser.parse(new InputStreamReader(resourceUrl.openStream(), Charsets.UTF_8));
InputStreamReader reader = null;
if("gzip".equals(connection.getContentEncoding()))
{
reader = new InputStreamReader(new GZIPInputStream(connection.getInputStream()), Charsets.UTF_8);
}
else
{
reader = new InputStreamReader(connection.getInputStream(), Charsets.UTF_8);
}
JsonRootNode data = parser.parse(reader);

for(int i = 0; i < data.getElements().size(); i++)
{
Expand Down Expand Up @@ -103,6 +117,7 @@ public void run()
try
{
URLConnection connection = url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:10.0) Gecko/20100101 Firefox/55.0");

final int fileLength = connection.getContentLength();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public String apply(JsonNode node)
{
URL url = new URL(libURL);
URLConnection connection = url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:10.0) Gecko/20100101 Firefox/55.0");
int fileLength = connection.getContentLength();
max += fileLength;
this.missingLibs.add(new LibEntry(libURL, libName, libPath, pack, fileLength, xz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private InputStreamReader getRemoteStream(String str) throws MalformedURLExcepti
URI uri = new URI(str);
URLConnection connection = uri.toURL().openConnection();
connection.setRequestProperty("Accept-Encoding", "gzip");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:10.0) Gecko/20100101 Firefox/55.0");
InputStreamReader reader = null;
if("gzip".equals(connection.getContentEncoding()))
{
Expand All @@ -232,4 +233,4 @@ private InputStreamReader getRemoteStream(String str) throws MalformedURLExcepti
}
return reader;
}
}
}

0 comments on commit 80a75e9

Please sign in to comment.