-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the input file or URL is binary, throw an exception
Prevents useless processing and apparent hangs Fixes #1192
- Loading branch information
Showing
7 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/org/jsoup/integration/servlets/FileServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.jsoup.integration.servlets; | ||
|
||
import org.jsoup.integration.ParseTest; | ||
import org.jsoup.integration.TestServer; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class FileServlet extends BaseServlet { | ||
public static final String Url = TestServer.map(FileServlet.class); | ||
public static final String ContentTypeParam = "contentType"; | ||
public static final String LocationParam = "loc"; | ||
public static final String DefaultType = "text/html"; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { | ||
String contentType = req.getParameter(ContentTypeParam); | ||
if (contentType == null) | ||
contentType = DefaultType; | ||
String location = req.getParameter(LocationParam); | ||
|
||
File file = ParseTest.getFile(location); | ||
if (file.exists()) { | ||
res.setContentType(contentType); | ||
res.setStatus(HttpServletResponse.SC_OK); | ||
|
||
ServletOutputStream out = res.getOutputStream(); | ||
Files.copy(file.toPath(), out); | ||
out.flush(); | ||
} else { | ||
res.setStatus(HttpServletResponse.SC_NOT_FOUND); | ||
} | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { | ||
doGet(req, res); | ||
} | ||
} |