1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit;
16
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.List;
20
21 import org.htmlunit.util.MimeType;
22 import org.htmlunit.util.NameValuePair;
23 import org.junit.jupiter.api.Test;
24 import org.openqa.selenium.WebDriver;
25
26
27
28
29
30
31
32
33
34 public class HttpWebConnection2Test extends WebDriverTestCase {
35
36
37
38
39
40 @Test
41 public void brokenGzip() throws Exception {
42 final byte[] content = new byte[] {-1};
43 final List<NameValuePair> headers = new ArrayList<>();
44 headers.add(new NameValuePair("Content-Encoding", "gzip"));
45 headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, String.valueOf(content.length)));
46
47 final MockWebConnection conn = getMockWebConnection();
48 conn.setResponse(URL_FIRST, content, 404, "OK", MimeType.TEXT_HTML, headers);
49
50
51 final WebDriver driver = loadPageWithAlerts2(URL_FIRST);
52 assertTrue(driver.getPageSource().length() > 100);
53 }
54
55
56
57
58 @Test
59 public void redirectBrokenGzip() throws Exception {
60 final String html = DOCTYPE_HTML + "<html></html>";
61
62 final List<NameValuePair> headers = Arrays.asList(new NameValuePair("Location", URL_SECOND.toString()),
63 new NameValuePair("Content-Encoding", "gzip"));
64 final MockWebConnection conn = getMockWebConnection();
65 conn.setResponse(URL_FIRST, "12", 302, "Some error", MimeType.TEXT_HTML, headers);
66 conn.setResponse(URL_SECOND, html);
67
68 final WebDriver driver = loadPageWithAlerts2(URL_FIRST);
69 assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
70 }
71
72 }