Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce common logic for Content.Source iterating over all chunks #11758

Open
scrat98 opened this issue May 6, 2024 · 0 comments
Open

Introduce common logic for Content.Source iterating over all chunks #11758

scrat98 opened this issue May 6, 2024 · 0 comments

Comments

@scrat98
Copy link
Contributor

scrat98 commented May 6, 2024

Jetty version(s)
12.0.8

Enhancement Description

Currently there are number of implementations that are doing the same thing: iterate over all chunks in Content.Source and make some transformation. Below the table with all those implementations

ByteBuffer asByteBuffer(Source source)                                                                                          ContentSourceByteBuffer
void asByteBuffer(Source source, Promise<ByteBuffer> promise)                                                                   ContentSourceByteBuffer
CompletableFuture<ByteBuffer> asByteBufferAsync(Source source)                                                                  ChunkAccumulator
CompletableFuture<ByteBuffer> asByteBufferAsync(Source source, int maxSize)                                                     ChunkAccumulator

CompletableFuture<byte[]> asByteArrayAsync(Source source, int maxSize)                                                          ChunkAccumulator

CompletableFuture<RetainableByteBuffer> asRetainableByteBuffer(Source source, ByteBufferPool pool, boolean direct, int maxSize) ChunkAccumulator

String asString(Source source)                                                                                                  ContentSourceString
String asString(Source source, Charset charset)                                                                                 ContentSourceString
void asString(Source source, Charset charset, Promise<String> promise)                                                          ContentSourceString
CompletableFuture<String> asStringAsync(Source source, Charset charset)                                                         ContentSourceString

InputStream asInputStream(Source source)                                                                                        ContentSourceInputStream

Flow.Publisher<Chunk> asPublisher(Source source)                                                                                ContentSourcePublisher

void consumeAll(Source source)                                                                                                  ContentSourceConsumer
void consumeAll(Source source, Callback callback)                                                                               ContentSourceConsumer

That may lead to the inconsistent behavior and multiplies surface of mistakes (for example ChunkAccumulator has a bug while ContentSourceByteBuffer don't have such bug #11756)

What do you think if it good idea to implement Content.Source iterating via Flow.Publisher as a reference and all other implementations will use it and just process chunks differently? It should also cover that issue #11755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant