Skip to content

Commit 6ffa831

Browse files
authored
Merge pull request #595 from jooby-project/584
org.jooby.Err: Not Found(404): /favicon.ico fix #584
2 parents 8c8dce7 + 4ee1179 commit 6ffa831

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.jooby.issues;
2+
3+
import org.jooby.test.ServerFeature;
4+
import org.junit.Test;
5+
6+
public class Issue584 extends ServerFeature {
7+
8+
{
9+
}
10+
11+
@Test
12+
public void silentFaviconRequest() throws Exception {
13+
request()
14+
.get("/favicon.ico")
15+
.expect(404)
16+
.expect("");
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.jooby.issues;
2+
3+
import org.jooby.test.ServerFeature;
4+
import org.junit.Test;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
public class Issue584b extends ServerFeature {
9+
10+
/** The logging system. */
11+
private final Logger log = LoggerFactory.getLogger(getClass());
12+
13+
{
14+
15+
err((req, rsp, err) -> {
16+
log.error("{}", req.path(), err);
17+
});
18+
}
19+
20+
@Test
21+
public void silentFaviconRequest() throws Exception {
22+
request()
23+
.get("/favicon.ico")
24+
.expect(404)
25+
.expect("");
26+
}
27+
}

jooby/src/main/java/org/jooby/internal/HttpHandlerImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,13 @@ private static List<Route> routes(final Set<Route.Definition> routeDefs, final S
430430
if (ex != null) {
431431
throw ex;
432432
}
433-
throw new Err(Status.NOT_FOUND, req.path(true));
433+
// favicon.ico
434+
if (path.equals("/favicon.ico")) {
435+
// default /favicon.ico handler:
436+
rsp.status(Status.NOT_FOUND).end();
437+
} else {
438+
throw new Err(Status.NOT_FOUND, req.path(true));
439+
}
434440
}
435441
}, method, path, "err", accept));
436442

0 commit comments

Comments
 (0)