Skip to content

Commit 7550e3c

Browse files
committed
Small bug-fixes and improvements
1 parent 0a011fc commit 7550e3c

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/main/java/express/http/response/Response.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ public class Response {
3535

3636
{
3737
// Initialize with default data
38-
contentType = MediaType._txt.getMIME();
39-
isClose = false;
40-
contentLength = 0;
41-
status = 200;
42-
LOGGER = Logger.getLogger(getClass().getSimpleName());
38+
this.contentType = MediaType._txt.getMIME();
39+
this.isClose = false;
40+
this.contentLength = 0;
41+
this.status = 200;
42+
this.LOGGER = Logger.getLogger(getClass().getSimpleName());
43+
this.LOGGER.setUseParentHandlers(false); // Disable default console log
4344
}
4445

4546
public Response(HttpExchange exchange) {
@@ -198,8 +199,7 @@ public boolean sendAttachment(Path file) {
198199
String dispo = "attachment; filename=\"" + file.getFileName() + "\"";
199200
setHeader("Content-Disposition", dispo);
200201

201-
send(file);
202-
return true;
202+
return send(file);
203203
}
204204

205205
/**
@@ -235,6 +235,8 @@ public boolean send(Path file) {
235235

236236
} catch (IOException e) {
237237
LOGGER.log(Level.INFO, "Failed to pipe file to outputstream.", e);
238+
close();
239+
return false;
238240
}
239241

240242
close();
@@ -249,7 +251,10 @@ public boolean isClosed() {
249251
}
250252

251253
/**
252-
* @return The logger from this reponse object.
254+
* Returns the logger which is concered for this Response object.
255+
* There is no default-handler active, if you want to log it you need to set an handler.
256+
*
257+
* @return The logger from this Response object.
253258
*/
254259
public Logger getLogger() {
255260
return LOGGER;

src/main/java/express/middleware/FileProvider.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ final class FileProvider implements HttpRequest {
2626
private FileProviderOptions OPTIONS;
2727
private String ROOT;
2828

29+
{
30+
this.LOGGER = Logger.getLogger(this.getClass().getSimpleName());
31+
this.LOGGER.setUseParentHandlers(false); // Disable default console log
32+
}
33+
2934
FileProvider(String root, FileProviderOptions options) throws IOException {
3035
File rootDir = new File(root);
3136

@@ -34,7 +39,6 @@ final class FileProvider implements HttpRequest {
3439

3540
this.ROOT = rootDir.getAbsolutePath();
3641
this.OPTIONS = options;
37-
this.LOGGER = Logger.getLogger(this.getClass().getSimpleName());
3842
}
3943

4044
@Override
@@ -127,8 +131,12 @@ private String getBaseName(Path path) {
127131
return index == -1 ? name : name.substring(0, index);
128132
}
129133

134+
130135
/**
131-
* @return The logger from this FileProvider instance.
136+
* Returns the logger which is concered for this FileProvilder object.
137+
* There is no default-handler active, if you want to log it you need to set an handler.
138+
*
139+
* @return The logger from this FileProvilder object.
132140
*/
133141
public Logger getLogger() {
134142
return LOGGER;

0 commit comments

Comments
 (0)