Fixing Chuncked Encoding
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -31,6 +31,13 @@
|
|||||||
<artifactId>flatlaf</artifactId>
|
<artifactId>flatlaf</artifactId>
|
||||||
<version>0.43</version>
|
<version>0.43</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-httpclient</groupId>
|
||||||
|
<artifactId>commons-httpclient</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,11 +5,10 @@ import ovh.alexisdelhaie.endpoint.utils.Tools;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
|
|
||||||
public class Application {
|
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();
|
ConfigurationProperties props = new ConfigurationProperties();
|
||||||
UIManager.setLookAndFeel(Tools.getLookAndFeel(props.getStringProperty("theme", "IntelliJ")));
|
UIManager.setLookAndFeel(Tools.getLookAndFeel(props.getStringProperty("theme", "IntelliJ")));
|
||||||
MainWindow dialog = new MainWindow(props);
|
MainWindow dialog = new MainWindow(props);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class AboutDialog extends JDialog {
|
|||||||
public static final int WIDTH = 740;
|
public static final int WIDTH = 740;
|
||||||
public static final int HEIGHT = 500;
|
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 JPanel contentPane;
|
||||||
private JLabel version;
|
private JLabel version;
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ public class HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SSLSocket s = (SSLSocket) factory.createSocket(host, port);
|
SSLSocket s = (SSLSocket) factory.createSocket(host, port);
|
||||||
s.setEnabledProtocols(new String[] { "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" });
|
|
||||||
s.setKeepAlive(false);
|
s.setKeepAlive(false);
|
||||||
s.setSoTimeout(timeout);
|
s.setSoTimeout(timeout);
|
||||||
if (allowDowngrade) {
|
if (allowDowngrade) {
|
||||||
|
|||||||
@@ -73,12 +73,7 @@ public class Response {
|
|||||||
private void parseBody() {
|
private void parseBody() {
|
||||||
if (headers.containsKey("transfer-encoding")) {
|
if (headers.containsKey("transfer-encoding")) {
|
||||||
if (headers.get("transfer-encoding").toLowerCase().contains("chunked")) {
|
if (headers.get("transfer-encoding").toLowerCase().contains("chunked")) {
|
||||||
ArrayList<String> chunks = Chunked.parse(body);
|
body = Chunked.parse(body);
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
for (String chunk : chunks) {
|
|
||||||
sb.append(chunk);
|
|
||||||
}
|
|
||||||
body = sb.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,22 @@
|
|||||||
package ovh.alexisdelhaie.endpoint.http.parsers;
|
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.math.BigInteger;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Chunked {
|
public class Chunked {
|
||||||
|
|
||||||
public static ArrayList<String> parse(String body) {
|
public static String parse(String body) {
|
||||||
ArrayList<String> result = new ArrayList<>();
|
String result;
|
||||||
try {
|
try {
|
||||||
body = body.strip();
|
ChunkedInputStream inputStream = new ChunkedInputStream(new ByteArrayInputStream(body.getBytes()));
|
||||||
int length; int pos;
|
result = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
do {
|
} catch (IOException e) {
|
||||||
pos = body.indexOf("\r\n");
|
result = e.getLocalizedMessage();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user