Skip to content

Commit 0a011fc

Browse files
committed
Improve Response class
1 parent bb83e44 commit 0a011fc

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/main/java/express/Express.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void listen(ExpressListener onStart) {
249249

250250
/**
251251
* Start the HTTP-Server on a specific port.
252-
* This method is asynchronous so be sure to add an listener or keep it in mind!
252+
* This method is asynchronous so be sure to add an listener or keep it in mind.
253253
*
254254
* @param onStart An listener which will be fired after the server is stardet.
255255
* @param port The port.

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,29 @@ public void send(String s) {
189189
* Normally this triggers an download event client-side.
190190
*
191191
* @param file The file which will be send as attachment.
192+
* @return True if the file was successfully send, false if the file doesn't exists or the respose is already closed.
192193
*/
193-
public void sendAttachment(Path file) {
194+
public boolean sendAttachment(Path file) {
194195
if (isClosed() || !Files.isRegularFile(file))
195-
return;
196+
return false;
196197

197198
String dispo = "attachment; filename=\"" + file.getFileName() + "\"";
198199
setHeader("Content-Disposition", dispo);
199200

200201
send(file);
202+
return true;
201203
}
202204

203205
/**
204206
* Send an entire file as response
205207
* The mime type will be automatically detected.
206208
*
207209
* @param file The file.
210+
* @return True if the file was successfully send, false if the file doesn't exists or the respose is already closed.
208211
*/
209-
public void send(Path file) {
212+
public boolean send(Path file) {
210213
if (isClosed() || !Files.isRegularFile(file))
211-
return;
214+
return false;
212215

213216
try {
214217
this.contentLength = Files.size(file);
@@ -235,6 +238,7 @@ public void send(Path file) {
235238
}
236239

237240
close();
241+
return true;
238242
}
239243

240244
/**
@@ -244,6 +248,13 @@ public boolean isClosed() {
244248
return this.isClose;
245249
}
246250

251+
/**
252+
* @return The logger from this reponse object.
253+
*/
254+
public Logger getLogger() {
255+
return LOGGER;
256+
}
257+
247258
private void sendHeaders() {
248259
try {
249260

0 commit comments

Comments
 (0)