Skip to content

Commit 7b401ac

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 db83cc5 commit 7b401ac

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

invoker/core/src/main/java/com/google/cloud/functions/invoker/http/HttpResponseImpl.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ public synchronized BufferedWriter getWriter() throws IOException {
9393
return writer;
9494
}
9595

96-
/**
97-
* Close the response, flushing all content.
98-
*/
96+
/** Close the response, flushing all content. */
9997
public void close() {
10098
try {
10199
IO.close(getOutputStream());
@@ -109,13 +107,11 @@ public void close() {
109107
}
110108

111109
/**
112-
* A {@link BufferedWriter} that does not buffer.
113-
* It is generally more efficient to buffer at the lower level,
114-
* since frequently total content is smaller than a single buffer and
115-
* the lower level buffer can turn a close into a last write that will avoid
116-
* chunking the response if at all possible. However, {@link BufferedWriter}
117-
* is in the API for {@link HttpResponse}, so we must return a writer of
118-
* that type.
110+
* A {@link BufferedWriter} that does not buffer. It is generally more efficient to buffer at the
111+
* lower level, since frequently total content is smaller than a single buffer and the lower level
112+
* buffer can turn a close into a last write that will avoid chunking the response if at all
113+
* possible. However, {@link BufferedWriter} is in the API for {@link HttpResponse}, so we must
114+
* return a writer of that type.
119115
*/
120116
private static class NonBufferedWriter extends BufferedWriter {
121117
private final Writer writer;

invoker/core/src/main/java/com/google/cloud/functions/invoker/runner/Invoker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ private static boolean isGcf() {
448448
/**
449449
* Wrapper that intercepts requests for {@code /favicon.ico} and {@code /robots.txt} and causes
450450
* them to produce a 404 status. Otherwise, they would be sent to the function code, like any
451-
* other URL, meaning that someone testing their function by using a browser as an HTTP client
452-
* can see two requests, one for {@code /favicon.ico} and one for {@code /} (or whatever).
451+
* other URL, meaning that someone testing their function by using a browser as an HTTP client can
452+
* see two requests, one for {@code /favicon.ico} and one for {@code /} (or whatever).
453453
*/
454454
private static class NotFoundHandler extends HandlerWrapper {
455455

invoker/core/src/test/java/com/google/cloud/functions/invoker/IntegrationTest.java

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ public void helloWorld() throws Exception {
253253
fullTarget("HelloWorld"),
254254
ImmutableList.of(
255255
TestCase.builder()
256-
.setExpectedResponseHeaders(ImmutableMap.of(
257-
"Content-Length", "*"))
256+
.setExpectedResponseHeaders(ImmutableMap.of("Content-Length", "*"))
258257
.setExpectedResponseText("hello\n")
259258
.build(),
260259
FAVICON_TEST_CASE,
@@ -271,23 +270,23 @@ public void bufferedWrites() throws Exception {
271270
TestCase.builder()
272271
.setUrl("/target?writes=2")
273272
.setExpectedResponseText("write 0\nwrite 1\n")
274-
.setExpectedResponseHeaders(ImmutableMap.of(
275-
"x-write-0", "true",
276-
"x-write-1", "true",
277-
"x-written", "true",
278-
"Content-Length", "16"
279-
))
273+
.setExpectedResponseHeaders(
274+
ImmutableMap.of(
275+
"x-write-0", "true",
276+
"x-write-1", "true",
277+
"x-written", "true",
278+
"Content-Length", "16"))
280279
.build(),
281280
TestCase.builder()
282281
.setUrl("/target?writes=2&flush=true")
283282
.setExpectedResponseText("write 0\nwrite 1\n")
284-
.setExpectedResponseHeaders(ImmutableMap.of(
285-
"x-write-0", "true",
286-
"x-write-1", "true",
287-
"x-written", "-",
288-
"Transfer-Encoding", "chunked"))
289-
.build()
290-
));
283+
.setExpectedResponseHeaders(
284+
ImmutableMap.of(
285+
"x-write-0", "true",
286+
"x-write-1", "true",
287+
"x-written", "-",
288+
"Transfer-Encoding", "chunked"))
289+
.build()));
291290
}
292291

293292
@Test
@@ -728,17 +727,26 @@ private void testFunction(
728727
.withMessage("Response to %s is %s %s", uri, response.getStatus(), response.getReason())
729728
.that(response.getStatus())
730729
.isEqualTo(testCase.expectedResponseCode());
731-
testCase.expectedResponseHeaders().ifPresent(map -> {
732-
for (Map.Entry<String, String> entry : map.entrySet()) {
733-
if ("*".equals(entry.getValue())) {
734-
expect.that(response.getHeaders().getFieldNamesCollection()).contains(entry.getKey());
735-
} else if ("-".equals(entry.getValue())) {
736-
expect.that(response.getHeaders().getFieldNamesCollection()).doesNotContain(entry.getKey());
737-
} else {
738-
expect.that(response.getHeaders().getValuesList(entry.getKey())).contains(entry.getValue());
739-
}
740-
}
741-
});
730+
testCase
731+
.expectedResponseHeaders()
732+
.ifPresent(
733+
map -> {
734+
for (Map.Entry<String, String> entry : map.entrySet()) {
735+
if ("*".equals(entry.getValue())) {
736+
expect
737+
.that(response.getHeaders().getFieldNamesCollection())
738+
.contains(entry.getKey());
739+
} else if ("-".equals(entry.getValue())) {
740+
expect
741+
.that(response.getHeaders().getFieldNamesCollection())
742+
.doesNotContain(entry.getKey());
743+
} else {
744+
expect
745+
.that(response.getHeaders().getValuesList(entry.getKey()))
746+
.contains(entry.getValue());
747+
}
748+
}
749+
});
742750
testCase
743751
.expectedResponseText()
744752
.ifPresent(text -> expect.that(response.getContentAsString()).isEqualTo(text));

0 commit comments

Comments
 (0)