feat(lambda-web): add a text/plain Content-Type to app responses that send none (#7285)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-02 07:47:05 -04:00
1 parent cf582c21be
commit f1c7098d9c
3 files changed
+31 -10

No files matched your search

@@ -590,7 +590,11 @@ public class LambdaWebDataPlane {
headers.set("Connection", "close");
}
/** The platform writes its own {@code Date} in place of the app's, but lets a {@code date} in lowercase pass. */
/**
* The platform writes its own {@code Date} in place of the app's, but lets a {@code date} in lowercase pass. It
* writes {@code text/plain} for an app that sends no {@code Content-Type}, even on a 204 or a HEAD, but not with a
* {@code Content-Length} of 0.
*/
static void copyResponseHeaders(MultiMap headers, HttpServerResponse out) {
out.headers().add("Date", LambdaWebErrorPages.platformDate(Instant.now()));
Set<String> dropped = new HashSet<>(DROPPED_RESPONSE_HEADERS);
@@ -600,10 +604,14 @@ public class LambdaWebDataPlane {
}
}
for (Map.Entry<String, String> header : headers) {
if (!"Date".equals(header.getKey()) && !dropped.contains(header.getKey().toLowerCase(Locale.ROOT))) {
out.headers().add(header.getKey(), header.getValue());
String name = header.getKey();
if (!"Date".equals(name) && !dropped.contains(name.toLowerCase(Locale.ROOT))) {
out.headers().add("Content-Type".equalsIgnoreCase(name) ? "Content-Type" : name, header.getValue());
}
}
if (!headers.contains("Content-Type") && !"0".equals(headers.get("Content-Length"))) {
out.headers().add("Content-Type", "text/plain; charset=utf-8");
}
}
static int port(String host, String scheme) {