Skip to content

Commit db83cc5

Browse files
committed
chore(implementation)!: use Jetty-12 core without servlets
Port the invoker to upgrade to Eclipse Jetty-12 version 12. Specifically using the new core APIs of Eclipse Jetty-12 that allow the overhead of a Servlet container to be avoided. Several optimizations are included, including the optimization that small writes can be buffered in such a way to avoid chunked responses when possible. BREAKING CHANGE: use Java 17 or above, as required by Eclipse Jetty-12.
1 parent 59c1cf4 commit db83cc5

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

invoker/core/src/main/java/com/google/cloud/functions/invoker/BackgroundFunctionExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ void serviceCloudEvent(CloudEvent cloudEvent) throws Exception {
322322

323323
/** Executes the user's background function. This can handle all HTTP methods. */
324324
@Override
325-
public void handle(String s, Request baseRequest, HttpServletRequest req,
326-
HttpServletResponse res) throws IOException, ServletException {
325+
public void handle(String s, Request baseRequest, HttpServletRequest req, HttpServletResponse res)
326+
throws IOException, ServletException {
327327
baseRequest.setHandled(true);
328328
String contentType = req.getContentType();
329329
try {

invoker/core/src/main/java/com/google/cloud/functions/invoker/HttpFunctionExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public static HttpFunctionExecutor forClass(Class<?> functionClass) {
6161
}
6262

6363
/** Executes the user's method, can handle all HTTP type methods. */
64-
public void handle(String s, Request baseRequest, HttpServletRequest req,
65-
HttpServletResponse res) throws IOException, ServletException {
64+
public void handle(String s, Request baseRequest, HttpServletRequest req, HttpServletResponse res)
65+
throws IOException, ServletException {
6666
baseRequest.setHandled(true);
6767
HttpRequestImpl reqImpl = new HttpRequestImpl(req);
6868
HttpResponseImpl respImpl = new HttpResponseImpl(res);

invoker/core/src/main/java/com/google/cloud/functions/invoker/TypedFunctionExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ static Optional<Type> handlerTypeArgument(Class<? extends TypedFunction<?, ?>> f
9898

9999
/** Executes the user's method, can handle all HTTP type methods. */
100100
@Override
101-
public void handle(String s, Request baseRequest, HttpServletRequest req,
102-
HttpServletResponse res) throws IOException, ServletException {
101+
public void handle(String s, Request baseRequest, HttpServletRequest req, HttpServletResponse res)
102+
throws IOException, ServletException {
103103
baseRequest.setHandled(true);
104104
HttpRequestImpl reqImpl = new HttpRequestImpl(req);
105105
HttpResponseImpl resImpl = new HttpResponseImpl(res);

invoker/core/src/test/java/com/google/cloud/functions/invoker/http/HttpTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ private interface HttpRequestTest {
108108

109109
/**
110110
* Tests methods on the {@link HttpRequest} object while the request is being serviced. We are not
111-
* guaranteed that the underlying {@link Request} object will still be valid when the
112-
* request completes, and in fact in Jetty it isn't. So we perform the checks in the context of
113-
* the handler, and report any exception back to the test method.
111+
* guaranteed that the underlying {@link Request} object will still be valid when the request
112+
* completes, and in fact in Jetty it isn't. So we perform the checks in the context of the
113+
* handler, and report any exception back to the test method.
114114
*/
115115
@Test
116116
public void httpRequestMethods() throws Exception {
@@ -299,8 +299,11 @@ private HttpRequestHandler(
299299
}
300300

301301
@Override
302-
public void handle(String s, org.eclipse.jetty.server.Request baseRequest,
303-
HttpServletRequest req, HttpServletResponse res)
302+
public void handle(
303+
String s,
304+
org.eclipse.jetty.server.Request baseRequest,
305+
HttpServletRequest req,
306+
HttpServletResponse res)
304307
throws IOException, ServletException {
305308
baseRequest.setHandled(true);
306309
try {
@@ -382,8 +385,11 @@ private HttpResponseHandler(
382385
}
383386

384387
@Override
385-
public void handle(String s, org.eclipse.jetty.server.Request baseRequest,
386-
HttpServletRequest req, HttpServletResponse resp) {
388+
public void handle(
389+
String s,
390+
org.eclipse.jetty.server.Request baseRequest,
391+
HttpServletRequest req,
392+
HttpServletResponse resp) {
387393
try {
388394
baseRequest.setHandled(true);
389395
testReference.get().test(new HttpResponseImpl(resp));

0 commit comments

Comments
 (0)