mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
#67 [CLI,DAEMON] Return proper return codes / status codes
This commit is contained in:
parent
fa7faf9961
commit
f2223552ad
21 changed files with 424 additions and 248 deletions
|
|
@ -15,15 +15,20 @@ abstract class BaseHandler implements HttpHandler {
|
|||
|
||||
protected static final String APPLICATION_XML = "application/xml";
|
||||
|
||||
static final int OK = 200;
|
||||
|
||||
protected static void write(final HttpExchange exchange, final byte[] content, final String contentType) throws IOException {
|
||||
write(exchange, contentType, os -> os.write(content));
|
||||
write(exchange, content, contentType, HttpStatus.SC_OK);
|
||||
}
|
||||
|
||||
protected static void write(final HttpExchange exchange, final String contentType, final Write write) throws IOException {
|
||||
protected static void write(final HttpExchange exchange, final byte[] content, final String contentType, final int statusCode)
|
||||
throws IOException {
|
||||
write(exchange, contentType, os -> os.write(content), statusCode);
|
||||
}
|
||||
|
||||
protected static void write(final HttpExchange exchange, final String contentType, final Write write, final int statusCode)
|
||||
throws IOException {
|
||||
exchange.getResponseHeaders().add("Content-Type", contentType);
|
||||
exchange.sendResponseHeaders(OK, 0);
|
||||
exchange.sendResponseHeaders(statusCode, 0);
|
||||
final OutputStream os = exchange.getResponseBody();
|
||||
write.write(os);
|
||||
os.close();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue