Close the InputStream before replacing the body

This fixes a bug where the InputStream would not always get closed full
logging is enabled.