-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.x: Media Context and streaming (#7396)
* Improved error messages in Http token validation * Fix intermittent failure when the server took time to shut down * Media writers now correctly handle streaming where needed, without buffering in memory. * Configurable max-in-memory-entity for server Signed-off-by: Tomas Langer <[email protected]>
- Loading branch information
1 parent
4de96df
commit a7e2091
Showing
30 changed files
with
738 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
http/media/media/src/main/java/io/helidon/http/media/InstanceWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2023 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.http.media; | ||
|
||
import java.io.OutputStream; | ||
import java.util.OptionalLong; | ||
|
||
/** | ||
* A writer dedicated to a specific instance. Method {@link #write(java.io.OutputStream)} will write the instance | ||
* to the output stream, method {@link #instanceBytes()} will provide all the bytes of entity. | ||
* The caller decided which method to call depending on results of {@link #alwaysInMemory()} and {@link #contentLength()}. | ||
*/ | ||
public interface InstanceWriter { | ||
/** | ||
* If we can determine the number of bytes to be written to the stream, provide the information here. | ||
* The returned number must be a valid content length (content-length >= 0) | ||
* | ||
* @return number of bytes or empty if not possible (or too expensive) to find out | ||
*/ | ||
OptionalLong contentLength(); | ||
|
||
/** | ||
* Whether the byte array is always available. If true {@link #instanceBytes()} will ALWAYS be called. | ||
* | ||
* @return whether the bytes will always be materialized in memory | ||
*/ | ||
boolean alwaysInMemory(); | ||
|
||
/** | ||
* Write the instance to the output stream. This method is NEVER called if {@link #alwaysInMemory()} is {@code true}, | ||
* otherwise this method is ALWAYS called if {@link #contentLength()} returns empty. | ||
* This method MAY be called if {@link #contentLength()} returns a value. | ||
* | ||
* @param stream to write to | ||
*/ | ||
void write(OutputStream stream); | ||
|
||
/** | ||
* Get the instance as byte array. This method is always called if {@link #alwaysInMemory()} returns {@code true}. | ||
* This method is NEVER called if {@link #contentLength()} returns empty. | ||
* This method MAY be called if {@link #contentLength()} returns a value. | ||
* | ||
* @return bytes of the instance | ||
*/ | ||
byte[] instanceBytes(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.