-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from zalando/feature/chunking
Chunking is now limited to the body itself
- Loading branch information
Showing
14 changed files
with
207 additions
and
210 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
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
67 changes: 0 additions & 67 deletions
67
logbook-core/src/main/java/org/zalando/logbook/ChunkingHttpLogWriter.java
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
logbook-core/src/main/java/org/zalando/logbook/ChunkingSink.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,54 @@ | ||
package org.zalando.logbook; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
import java.io.IOException; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.stream.StreamSupport.stream; | ||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
import static org.zalando.fauxpas.FauxPas.throwingConsumer; | ||
|
||
@API(status = EXPERIMENTAL) | ||
public final class ChunkingSink implements Sink { | ||
|
||
private static final int MIN_MAX_DELTA = 16; | ||
|
||
private final Sink delegate; | ||
private final int minChunkSize; | ||
private final int maxChunkSize; | ||
|
||
public ChunkingSink(final Sink delegate, final int size) { | ||
this.delegate = delegate; | ||
|
||
if (size <= 0) { | ||
throw new IllegalArgumentException("size is expected to be greater than zero"); | ||
} | ||
this.minChunkSize = size > MIN_MAX_DELTA ? size - MIN_MAX_DELTA : size; | ||
this.maxChunkSize = size; | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return delegate.isActive(); | ||
} | ||
|
||
@Override | ||
public void write(final Precorrelation precorrelation, final HttpRequest original) throws IOException { | ||
chunk(original) | ||
.map(chunk -> new BodyReplacementHttpRequest(original, chunk)) | ||
.forEach(throwingConsumer(replaced -> delegate.write(precorrelation, replaced))); | ||
} | ||
|
||
@Override | ||
public void write(final Correlation correlation, final HttpRequest request, final HttpResponse original) throws IOException { | ||
chunk(original) | ||
.map(chunk -> new BodyReplacementHttpResponse(original, chunk)) | ||
.forEach(throwingConsumer(replaced -> delegate.write(correlation, request, replaced))); | ||
} | ||
|
||
private Stream<String> chunk(final HttpMessage message) throws IOException { | ||
return stream(new ChunkingSpliterator(message.getBodyAsString(), minChunkSize, maxChunkSize), false); | ||
} | ||
|
||
} |
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
84 changes: 0 additions & 84 deletions
84
logbook-core/src/test/java/org/zalando/logbook/ChunkingHttpLogWriterTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.