Skip to content

Commit 422fe17

Browse files
duonglaiquangrbri
authored andcommitted
DefaultPageCreator: force content sniffing for */* content type
1 parent 732a0e0 commit 422fe17

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/org/htmlunit/DefaultPageCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static PageType determinePageType(final String contentType) {
155155
*/
156156
public static PageType determinePageType(final WebResponse webResponse) throws IOException {
157157
final String contentType = webResponse.getContentType();
158-
if (!StringUtils.isEmptyOrNull(contentType)) {
158+
if (!StringUtils.isEmptyOrNull(contentType) && !"*/*".equals(contentType)) {
159159
return determinePageType(contentType);
160160
}
161161

src/test/java/org/htmlunit/DefaultPageCreatorTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @author Marc Guillemot
3939
* @author Ahmed Ashour
4040
* @author Ronald Brill
41+
* @author Lai Quang Duong
4142
*/
4243
public class DefaultPageCreatorTest extends WebServerTestCase {
4344

@@ -377,6 +378,32 @@ protected void doGet(final HttpServletRequest request, final HttpServletResponse
377378
}
378379
}
379380

381+
/**
382+
* @throws Exception if the test fails
383+
*/
384+
@Test
385+
public void wildcardContentType() throws Exception {
386+
final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
387+
servlets.put("/test", WildcardContentTypeServlet.class);
388+
startWebServer("./", servlets);
389+
390+
final WebClient client = getWebClient();
391+
assertTrue(client.getPage(URL_FIRST + "test") instanceof HtmlPage);
392+
}
393+
394+
/**
395+
* Servlet for {@link #wildcardContentType()}.
396+
*/
397+
public static class WildcardContentTypeServlet extends HttpServlet {
398+
/** {@inheritDoc} */
399+
@Override
400+
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
401+
response.setContentType("*/*");
402+
final Writer writer = response.getWriter();
403+
writer.write("<html><head></head><body>Hello World</body></html>");
404+
}
405+
}
406+
380407
/**
381408
* @throws Exception if the test fails
382409
*/

0 commit comments

Comments
 (0)