Add TransformRequestBodyAction
and TransformResponseBodyAction
to inspect/replace quickly HTTP bodies
#395
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.
This pull request introduces two new actions:
TransformResponseBodyAction
andTransformRequestBodyAction
. These actions offer a simpler and more intuitive alternative to ISubstitution, enabling conditional modifications on request or response bodies.You can leverage this new feature to inspect and conditionally edit request or response bodies dynamically.
Usage
Access to this feature is possible:
TransformResponseBodyAction
andTransformRequestBodyAction
.Example: Uppercasing any response body text
Another example that returns the SHA1 body hash instead of the original content
Implementation Details
In all cases, the caller must supply a function that accepts the original content along with any contextual settings, returning the transformed content as a
string
,byte[]
, orStream
.Under the hood, this functionality utilizes
IStreamSubstitution
, which automatically manages size control headers (such as Content-Length, chunked transfer encoding). Additionally, encoded content (gzip, deflate, etc.) is preprocessed transparently by Fluxzy.Memory Considerations
Note that transforming responses into byte arrays or strings involves loading the entire response content into memory.