I have following controller in a Spring Boot application which accept and return a binary stream. I need to accept a steam, encrypt it and at the same time return the result. This streams can be pretty large and cannot be held in memory:
@PostMapping(value = "/encrypt-stream/", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void encryptStream(HttpServletRequest request, HttpServletResponse response){
OutputStream os = response.getOutputStream();
InputStream is = request.getInputStream();
String checksum = encryptionService.encrypt(is, os);
response.setHeader("checksum", checksum);
}
I need to send the a header (checksum
) based on the result of the service call (encryptionService.encrypt()
) within the controller.
Setting header on HttpServletResponse
is not working.
I have looked at implementing Filter
class however it only works when you set the header before .doFilter()
call. My issue is the header value is calculated after.
Also, same issue with implementing a HandlerInterceptorAdapter
.