Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ServletNameAttribute implements ExchangeAttribute {

public static final ExchangeAttribute INSTANCE = new ServletNameAttribute();
public static final String NAME = "Servlet Name";
public static final String UNDEFINED = "No-Servlet";

private ServletNameAttribute() {

Expand All @@ -43,7 +44,11 @@ private ServletNameAttribute() {
@Override
public String readAttribute(final HttpServerExchange exchange) {
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
return src.getCurrentServlet().getManagedServlet().getServletInfo().getName();
if (src != null) {
return src.getCurrentServlet().getManagedServlet().getServletInfo().getName();
} else {
return UNDEFINED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the reasoning behind intentionally returning "No-Servlet" here?

I was thinking that returning null would be sufficient, as it gets logged as - in the access log by default. This would also align with other ExchangeAttributes, which typically return null when a value isn't available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UX, looks better than "null".

Copy link
Contributor

@msfm msfm Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, my suggestion of returning null does not result in the string "null" being logged. Instead, the access log mechanism converts it to -, which is the standard convention for an empty value in Undertow.

My main concern is consistency. All other ExchangeAttributes (like RequestHeaderAttribute, ResponseHeaderAttribute, RemoteUserAttribute, etc.) return null and are logged as -. Introducing a custom "No-Servlet" string here would create a special case and make the logs less uniform.

For this reason, I still believe that returning null is the most appropriate approach.

}
}

@Override
Expand Down
Loading