-
Notifications
You must be signed in to change notification settings - Fork 86
Replacement for binary content of multipart requests #369
Conversation
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.
Thanks for your contribution. An alternative to creating a separate processor would be to just add the media type to the set of media types in BinaryReplacementContentModifier
. But I also prefer a separate processor because in some cases it makes sense that the content of multipart requests ends up in the document. This is very unlikely for images and PDFs (covered by the existing BinaryReplacementContentModifier
). With keeping them separate, every user can decide to go with both, either one or none.
import org.springframework.restdocs.operation.preprocess.OperationPreprocessor; | ||
import org.springframework.restdocs.operation.preprocess.OperationResponsePreprocessor; | ||
import org.springframework.restdocs.operation.preprocess.Preprocessors; | ||
import org.springframework.restdocs.operation.preprocess.*; |
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.
Please expand the imports again. We are avoiding *
imports. But I also know that we neither have this documented nor enforced at the moment.
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.
Fixed
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
public class MultipartContentOperationPreprocessor extends OperationPreprocessorAdapter { |
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.
Is there a reason why you are extending OperationPreprocessorAdapter
instead of implementing ContentModifier
like the BinaryReplacementContentModifier
? Implementing ContentModifier
makes the code a bit simpler.
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.
I extending OperationPreprocessorAdapter because ContentModifier takes original content (look at ContentModifyingOperationPreprocessor. In case of multipart/form-data content is empty byte array and all binary data holds in parts
field.
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.
Thanks, this makes sense.
…y content of multipart/form-data requests
@@ -0,0 +1,44 @@ | |||
package capital.scalable.restdocs.response; |
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.
The headers above the new files are missing but I can add them as well. We have a Maven plugin configured that adds them automatically.
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
public class MultipartContentOperationPreprocessor extends OperationPreprocessorAdapter { |
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.
Thanks, this makes sense.
This PR adds MultipartContentOperationPreprocessor for replacing binary content of multipart/form-data requests