Skip to content

Commit

Permalink
Add new sendEarlyHints() method
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jul 19, 2024
1 parent d8b3a70 commit 0595445
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
21 changes: 20 additions & 1 deletion api/src/main/java/jakarta/servlet/http/HttpServletResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -251,6 +251,17 @@ default void sendRedirect(String location, int sc) throws IOException {
*/
void sendRedirect(String location, int sc, boolean clearBuffer) throws IOException;

/**
* 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();

/**
* Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the
* epoch. If the header had already been set, the new value overwrites all previous values. The
Expand Down Expand Up @@ -508,6 +519,14 @@ default Supplier<Map<String, String>> getTrailerFields() {
*/
int SC_SWITCHING_PROTOCOLS = 101;

/**
* Status code (103) indicating that the server is likely to send a final response containing the headers present in
* this informational response.
*
* @since Servlet 6.2
*/
int SC_EARLY_HINTS = 103;

/**
* Status code (200) indicating the request succeeded normally.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -141,6 +141,16 @@ public void sendRedirect(String location, int sc, boolean clearBuffer) throws IO
this._getHttpServletResponse().sendRedirect(location, sc, clearBuffer);
}

/**
* The default behavior of this method is to call sendEarlyHints() on the wrapped response object.
*
* @since Servlet 6.2
*/
@Override
public void sendEarlyHints() {
this._getHttpServletResponse().sendEarlyHints();
}

/**
* The default behavior of this method is to call setDateHeader(String name, long date) on the wrapped response object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public void sendRedirect(String location, int sc, boolean clearBuffer) throws IO

}

@Override
public void sendEarlyHints() {

}

@Override
public void setDateHeader(String name, long date) {

Expand Down
4 changes: 3 additions & 1 deletion spec/src/main/asciidoc/servlet-spec-body.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8579,7 +8579,9 @@ Jakarta Servlet {spec-version} specification developed under the Jakarta EE Work

=== Changes Since Jakarta Servlet 6.1

TBD.
link:https://github.com/eclipse-ee4j/servlet-api/issues/542[Issue 542]::
Add support for RFC 8297 (Early Hints) via a new method `sendEarlyHints()` on
the `HttpServletResponse`

=== Changes Since Jakarta Servlet 6.0

Expand Down

0 comments on commit 0595445

Please sign in to comment.