Skip to content

Commit a2f9871

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 2e99c43 commit a2f9871

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
public class HttpResponseImpl implements HttpResponse {
3838
private final Response response;
39-
private ContentSinkOutputStream contentSinkOutputStream;
39+
private ContentSinkOutputStream outputStream;
4040
private BufferedWriter writer;
4141
private Charset charset;
4242

@@ -84,22 +84,22 @@ public Map<String, List<String>> getHeaders() {
8484
public OutputStream getOutputStream() {
8585
if (writer != null) {
8686
throw new IllegalStateException("getWriter called");
87-
} else if (contentSinkOutputStream == null) {
87+
} else if (outputStream == null) {
8888
Request request = response.getRequest();
8989
int outputBufferSize = request.getConnectionMetaData().getHttpConfiguration()
9090
.getOutputBufferSize();
9191
BufferedContentSink bufferedContentSink = new BufferedContentSink(response,
9292
request.getComponents().getByteBufferPool(),
9393
false, outputBufferSize / 2, outputBufferSize);
94-
contentSinkOutputStream = new ContentSinkOutputStream(bufferedContentSink);
94+
outputStream = new ContentSinkOutputStream(bufferedContentSink);
9595
}
96-
return contentSinkOutputStream;
96+
return outputStream;
9797
}
9898

9999
@Override
100100
public synchronized BufferedWriter getWriter() throws IOException {
101101
if (writer == null) {
102-
if (contentSinkOutputStream != null) {
102+
if (outputStream != null) {
103103
throw new IllegalStateException("getOutputStream called");
104104
}
105105

@@ -117,9 +117,9 @@ public synchronized BufferedWriter getWriter() throws IOException {
117117
public void close(Callback callback) {
118118
try {
119119
// The writer has been constructed to do no buffering, so it does not need to be flushed
120-
if (contentSinkOutputStream != null) {
120+
if (outputStream != null) {
121121
// Do an asynchronous close, so large buffered content may be written without blocking
122-
contentSinkOutputStream.close(callback);
122+
outputStream.close(callback);
123123
} else {
124124
callback.succeeded();
125125
}

0 commit comments

Comments
 (0)