Jakarta Servlet 6.2 の主な変更点


103 Early Hints ステータスコードのサポート追加

Early Hints (RFC 8297) は HTTP の新しいステータスコードです。 これは、サーバーがメインのレスポンスに先立ち、CSSなどのURLを link フィールド として返却する場合のステータスコードになります。

ブラウザはメインのレスポンスを受信する前に、CSSファイルのリクエストを送ることができ、ページ表示の高速化が期待できる というものです。

以下のメソッドが追加されました。

public interface HttpServletResponse extends ServletResponse {
    /**
     * Sends a 103 response to the client using the current response headers. This method does not commit the response and
     * may be called multiple times before the response is committed. The current response headers may include some headers
     * that have been added automatcially by the container.
     * <p>
     * This method has no effect if called after the response has been committed.
     *
     * @since Servlet 6.2
     */
    void sendEarlyHints();
}

以下のように Link ヘッダーを設定すれば、

response.setHeader("Link", "</css/style.css>; rel=preload; as=style");
response.sendEarlyHints();

以下のようなレスポンスを返します。

103 Early Hints
Link: </css/style.css>; rel=preload; as=style


無効な If-Modified-Since ヘッダー値は無視されるべき

RFC 9110 では、無効な If-Modified-Sinceヘッダー値は無視されるべきと規定されているが、ヘッダー値が無効な場合に IllegalArgumentExceptionがスローされていました。

以下のように無視するように修正されました。

public abstract class HttpServlet extends GenericServlet {

    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getMethod();

        if (method.equals(METHOD_GET)) {
            long lastModified = getLastModified(req);
            if (lastModified == -1) {
                // servlet doesn't support if-modified-since, no reason
                // to go through further expensive logic
                doGet(req, resp);
            } else {
                long ifModifiedSince;
                try {
                    ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE);
                } catch (IllegalArgumentException iae) {
                    // RFC 9110, 13.1.3 - Invalid If-Modified-Since must be ignored
                    ifModifiedSince = -1;
                }


その他

あとは、エッジケースにおける軽微な仕様充足程度なので、あまり気にしなくて良いでしょう。