Fixing Chuncked Encoding
This commit is contained in:
@@ -5,11 +5,10 @@ import ovh.alexisdelhaie.endpoint.utils.Tools;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) throws UnsupportedLookAndFeelException, IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
public static void main(String[] args) throws UnsupportedLookAndFeelException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
ConfigurationProperties props = new ConfigurationProperties();
|
||||
UIManager.setLookAndFeel(Tools.getLookAndFeel(props.getStringProperty("theme", "IntelliJ")));
|
||||
MainWindow dialog = new MainWindow(props);
|
||||
|
||||
@@ -13,7 +13,7 @@ public class AboutDialog extends JDialog {
|
||||
public static final int WIDTH = 740;
|
||||
public static final int HEIGHT = 500;
|
||||
|
||||
public static final String VERSION = "0.1.5.1";
|
||||
public static final String VERSION = "0.1.5.2";
|
||||
|
||||
private JPanel contentPane;
|
||||
private JLabel version;
|
||||
|
||||
@@ -126,7 +126,6 @@ public class HttpClient {
|
||||
}
|
||||
|
||||
SSLSocket s = (SSLSocket) factory.createSocket(host, port);
|
||||
s.setEnabledProtocols(new String[] { "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" });
|
||||
s.setKeepAlive(false);
|
||||
s.setSoTimeout(timeout);
|
||||
if (allowDowngrade) {
|
||||
|
||||
@@ -73,12 +73,7 @@ public class Response {
|
||||
private void parseBody() {
|
||||
if (headers.containsKey("transfer-encoding")) {
|
||||
if (headers.get("transfer-encoding").toLowerCase().contains("chunked")) {
|
||||
ArrayList<String> chunks = Chunked.parse(body);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (String chunk : chunks) {
|
||||
sb.append(chunk);
|
||||
}
|
||||
body = sb.toString();
|
||||
body = Chunked.parse(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
package ovh.alexisdelhaie.endpoint.http.parsers;
|
||||
|
||||
import org.apache.commons.httpclient.ChunkedInputStream;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Chunked {
|
||||
|
||||
public static ArrayList<String> parse(String body) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
public static String parse(String body) {
|
||||
String result;
|
||||
try {
|
||||
body = body.strip();
|
||||
int length; int pos;
|
||||
do {
|
||||
pos = body.indexOf("\r\n");
|
||||
length = Integer.parseInt(body.substring(0, pos), 16);
|
||||
result.add(body.substring(pos + 2, length));
|
||||
body = body.substring(pos + 2 + length);
|
||||
} while (!body.isEmpty());
|
||||
} catch (NumberFormatException e) {
|
||||
result.add(body);
|
||||
ChunkedInputStream inputStream = new ChunkedInputStream(new ByteArrayInputStream(body.getBytes()));
|
||||
result = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
result = e.getLocalizedMessage();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user