-
Notifications
You must be signed in to change notification settings - Fork 264
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
Chunking is now limited to the body itself #449
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about going on step further and hide the headers, like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would move it a bit closer to be a properly usable feature. Until now it was basically breaking our format, but even with my change it's still a gimmick and not 100% "production-ready".
As an example a parser wouldn't know that this is a chunk. I believe it would be nice to get attribute-support in (see #381) and use that to tag individual chunks with their number. Parsers like Scalyr could then exclude anything with
$chunk > 1
when counting requests/responses (as an example).