Skip to content

Commit c474979

Browse files
authored
Merge pull request #9963 from loicmathieu/azur-aws-function-improvements
Align buffer size for Azure and AWS functions
2 parents 1cdc2e7 + 05cd043 commit c474979

File tree

2 files changed

+8
-5
lines changed
  • extensions
    • amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http
    • azure-functions-http/runtime/src/main/java/io/quarkus/azure/functions/resteasy/runtime

2 files changed

+8
-5
lines changed

extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
public class LambdaHttpHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> {
4141
private static final Logger log = Logger.getLogger("quarkus.amazon.lambda.http");
4242

43+
private static final int BUFFER_SIZE = 8096;
44+
4345
private static Headers errorHeaders = new Headers();
4446
static {
4547
errorHeaders.putSingle("Content-Type", "application/json");
@@ -122,7 +124,7 @@ public void handleMessage(Object msg) {
122124
responseBuilder.setBase64Encoded(true);
123125
responseBuilder.setBody(Base64.getMimeEncoder().encodeToString(baos.toByteArray()));
124126
} else {
125-
responseBuilder.setBody(new String(baos.toByteArray(), "UTF-8"));
127+
responseBuilder.setBody(new String(baos.toByteArray(), StandardCharsets.UTF_8));
126128
}
127129
}
128130
future.complete(responseBuilder);
@@ -205,8 +207,8 @@ private AwsProxyResponse nettyDispatch(InetSocketAddress clientAddress, AwsProxy
205207
}
206208

207209
private ByteArrayOutputStream createByteStream() {
208-
ByteArrayOutputStream baos;// todo what is right size?
209-
baos = new ByteArrayOutputStream(1000);
210+
ByteArrayOutputStream baos;
211+
baos = new ByteArrayOutputStream(BUFFER_SIZE);
210212
return baos;
211213
}
212214

extensions/azure-functions-http/runtime/src/main/java/io/quarkus/azure/functions/resteasy/runtime/BaseFunction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class BaseFunction {
3737
protected static final String deploymentStatus;
3838
protected static boolean started = false;
3939

40+
private static final int BUFFER_SIZE = 8096;
41+
4042
static {
4143
StringWriter error = new StringWriter();
4244
PrintWriter errorWriter = new PrintWriter(error, true);
@@ -106,7 +108,7 @@ protected HttpResponseMessage nettyDispatch(HttpRequestMessage<Optional<byte[]>>
106108

107109
private static ByteArrayOutputStream createByteStream() {
108110
ByteArrayOutputStream baos;
109-
baos = new ByteArrayOutputStream(500);
111+
baos = new ByteArrayOutputStream(BUFFER_SIZE);
110112
return baos;
111113
}
112114

@@ -136,7 +138,6 @@ public void handleMessage(Object msg) {
136138
if (msg instanceof HttpContent) {
137139
HttpContent content = (HttpContent) msg;
138140
if (baos == null) {
139-
// todo what is right size?
140141
baos = createByteStream();
141142
}
142143
int readable = content.content().readableBytes();

0 commit comments

Comments
 (0)