Skip to content

Commit e74b9e8

Browse files
committed
refactor: Extract GET_HEAD constant for duplicated Allow header value
1 parent 7dc8f9f commit e74b9e8

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/main/java/com/retailsvc/http/Handlers.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public final class Handlers {
3434

3535
private static final Logger LOG = LoggerFactory.getLogger(Handlers.class);
3636
private static final String ALLOW = "Allow";
37+
private static final String GET_HEAD = "GET, HEAD";
3738

3839
private Handlers() {}
3940

@@ -251,7 +252,7 @@ public static RequestHandler aliveHandler() {
251252
return req ->
252253
switch (req.method()) {
253254
case GET, HEAD -> Response.empty();
254-
default -> Response.status(HTTP_BAD_METHOD).withHeader(ALLOW, "GET, HEAD");
255+
default -> Response.status(HTTP_BAD_METHOD).withHeader(ALLOW, GET_HEAD);
255256
};
256257
}
257258

@@ -276,7 +277,7 @@ public static RequestHandler healthHandler(Supplier<HealthOutcome> probe) {
276277
Objects.requireNonNull(probe, "probe");
277278
return req -> {
278279
if (req.method() != GET && req.method() != HEAD) {
279-
return Response.status(HTTP_BAD_METHOD).withHeader(ALLOW, "GET, HEAD");
280+
return Response.status(HTTP_BAD_METHOD).withHeader(ALLOW, GET_HEAD);
280281
}
281282
boolean up;
282283
List<Dependency> dependencies;
@@ -335,7 +336,7 @@ private static RequestHandler resourceHandler(ResourceSource source) {
335336
Response.status(HTTP_OK)
336337
.withContentType(contentType)
337338
.withHeader("Content-Length", String.valueOf(length));
338-
default -> Response.status(HTTP_BAD_METHOD).withHeader(ALLOW, "GET, HEAD");
339+
default -> Response.status(HTTP_BAD_METHOD).withHeader(ALLOW, GET_HEAD);
339340
};
340341
}
341342
}

0 commit comments

Comments
 (0)