tomdesair / tus-java-server

Library to receive tus v1.0.0 file uploads in a Java server environment
MIT License
131 stars 62 forks source link

Undertow throws exception when TUS tries to respond with 409 or some other error status #40

Open OverDrone opened 3 years ago

OverDrone commented 3 years ago

CoreDefaultResponseHeadersHandler always writes header Content-Length=0 If some error detected, like incorrect offset, TUS calls HttpServletResponse.sendError() with some message. In other words there is nonempty response with header Content-Length=0. Undertow throws exception, probably because it allocates output buffer based on Content-Length header.

How to fix:

Remove setting Content-Length=0 from CoreDefaultResponseHeadersHandler. Or overwrite Content-Length header before calling HttpServletResponse.sendError()

Lesrac commented 3 years ago

Is there a way to resolve this? As there is no way to return a content in case that we experience an error after upload (as we do some checks after the file upload finished). And if we simply remove the "Content-Length=0" that is set by default, we don't get any Content-Length at all anymore.