Skip to content

Commit

Permalink
Allows the webserver's write buffer size to be set to 0 (or less). Th…
Browse files Browse the repository at this point in the history
…e underlying output stream shall not be wrapped into a buffered output stream one unless this value is greater than 0.
  • Loading branch information
spericas committed Oct 2, 2024
1 parent 1127d96 commit 0c9f7c2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.webserver.tests;

import io.helidon.webclient.http1.Http1Client;
import io.helidon.webserver.WebServerConfig;
import io.helidon.webserver.testing.junit5.ServerTest;
import io.helidon.webserver.testing.junit5.SetUpServer;

@ServerTest
class OutputStreamBufferSizeTest extends OutputStreamTest {

OutputStreamBufferSizeTest(Http1Client client) {
super(client);
}

@SetUpServer
static void setup(WebServerConfig.Builder builder) {
builder.writeBufferSize(0); // should accept buffer size of 0
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,7 +59,7 @@ void verifyAutoFlush() {
}
}

private static class Service {
protected static class Service {

public static void outputStream(ServerRequest req, ServerResponse res) throws IOException {
InputStream in = new ByteArrayInputStream("Hello World".getBytes(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,15 +753,19 @@ private void writeContent(BufferData buffer) throws IOException {
* A special stream that provides buffering for a delegate and special handling
* of close logic. Note that due to some locking issues in the JDK, this class
* must use delegation with {@link BufferedOutputStream} instead of subclassing.
*
* <p>If the buffer size is less or equal to zero, it will not wrap the
* {@link io.helidon.webserver.http1.Http1ServerResponse.BlockingOutputStream}
* with a {@link java.io.BufferedOutputStream}.
*/
static class ClosingBufferedOutputStream extends OutputStream {

private final BlockingOutputStream delegate;
private final BufferedOutputStream bufferedDelegate;
private final OutputStream bufferedDelegate;

ClosingBufferedOutputStream(BlockingOutputStream out, int size) {
this.delegate = out;
this.bufferedDelegate = new BufferedOutputStream(out, size);
this.bufferedDelegate = size <= 0 ? out : new BufferedOutputStream(out, size);
}

@Override
Expand Down

0 comments on commit 0c9f7c2

Please sign in to comment.