Fix a bug where HttpContentEncoder generates an empty chunk even if it's not the last chunk

- Fixes #1312
- Added more test cases to ensure the fix