Fixing Chuncked Encoding

This commit is contained in:
Alexis Delhaie
2020-12-10 11:47:40 +01:00
parent bb16995dbb
commit b82ce01f9d
6 changed files with 21 additions and 22 deletions

View File

@@ -31,6 +31,13 @@
<artifactId>flatlaf</artifactId>
<version>0.43</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
</project>

View File

@@ -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);

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);
}
}
}

View File

@@ -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;
}