Early response warning issued even after canceeling the connection

scala

(Simao) #1

I am writing an endpoint a curl client uses to send a big file, but I want to be able to terminate the request early if some conditions are met and redirect the client to a different url.

I am cancelling the connection with: entity.dataBytes.runWith(Sink.cancelled) and then returning redirect(uri, StatusCodes.Found)redirect(uri, StatusCodes.Found)

This actually works, curl does not receive 100 Continue, cancels the upload and finishes the request. However, in the logs I always get the message:

Sending an 2xx 'early' response before end of request was received... Note that the connection will be closed after this response. Also, many clients will not read early responses! Consider only issuing this response after the request data has been completely read!

Is this expected behavior?

Even though the response is a success code, it’s not a 2xx, but besides that, I am cancelling the connection anyway, so I should not see this warning?

If I discard the bytes instead of cancelling I don’t get this warning, but this would force the client to upload a file just so the server can ignore the bytes.