TitleCrawlerHandler : Return 400 on empty body.

This commit is contained in:
Dmitry Voronin 2024-09-24 12:08:25 +03:00
parent 236e35eebc
commit 09f2ff2903
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k

View file

@ -30,6 +30,13 @@ class TitleCrawlerHandler extends HttpHandler, Handler {
// I don't know if this one is ugly, but I wanted to show off a bit. // I don't know if this one is ugly, but I wanted to show off a bit.
extension (exchange: HttpExchange) private def sendResponse(request: Array[Byte]): Unit = { extension (exchange: HttpExchange) private def sendResponse(request: Array[Byte]): Unit = {
// Check for empty body.
if (request.isEmpty) {
exchange.sendResponseHeaders(400, -1)
return
}
// Start processing.
exchange.sendResponseHeaders(200, 0) exchange.sendResponseHeaders(200, 0)
val reader = new BufferedReader(new InputStreamReader(ByteArrayInputStream(request))) val reader = new BufferedReader(new InputStreamReader(ByteArrayInputStream(request)))
val output = exchange.getResponseBody val output = exchange.getResponseBody