Silent handling of bridge errors

No longer reporting breaking pipes on bridges
#11
This commit is contained in:
Norbi Peti 2018-09-15 14:05:12 +02:00
parent a4cf26556f
commit 73b02518a4
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -53,9 +53,13 @@ public class BridgePage extends Page {
return new Response(400, "No connection", exchange);
if (s.isClosed())
return new Response(410, "Socket Gone", exchange);
try {
exchange.sendResponseHeaders(200, 0); // Chunked transfer, any amount of data
copyStream(s.getInputStream(), exchange.getResponseBody());
exchange.getResponseBody().close(); // It'll only get here when the communication is already done
} catch (IOException ex) { //Failed to send it over HTTP, GET connection closed
closeSocket(exchange); //We only have one GET, connection over
}
return null; // Response already sent
case "DELETE":
System.out.println("[BWM] [" + id + "] delet this");
@ -65,7 +69,12 @@ public class BridgePage extends Page {
return new Response(403, "Unknown request", exchange);
}
} catch (IOException e) {
throw new RuntimeException(e);
if (e instanceof SocketException) {
closeSocket(exchange);
return new Response(410, "Socket Gone because of error: " + e, exchange);
}
e.printStackTrace();
return new Response(500, "Internal Server Error: " + e, exchange);
}
}
@ -92,8 +101,7 @@ public class BridgePage extends Page {
return;
try {
socket.close();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (IOException ignored) {
}
connections.values().remove(socket);
}