Detect the end of the request with close instead of finish