shaka-project / shaka-packager

A media packaging and development framework for VOD and Live DASH and HLS applications, supporting Common Encryption for Widevine and other DRM Systems.
https://shaka-project.github.io/shaka-packager/
Other
2k stars 510 forks source link

fix: Fix flush/close semantics for HTTP files, improve testing #1232

Closed joeyparrish closed 1 year ago

joeyparrish commented 1 year ago

All HTTP-based tests now use an embedded test server instead of httpbin.org, which makes them much faster and more reliable.

These more reliable tests also exposed some issues that began recently with PR #1201. HttpFile's Flush() semantics were different than those documented for files in general. Flush() used to close the file for uploading, so that no further writes were allowed, but the documentation stated that it would only flush data to its destination. PR #1201 brought HttpFile's Flush() in line with the docs, but gave us no way to terminate a chunked upload.

This adds a new method to File called CloseForWriting(), which terminates a chunked upload for HttpFile. The only other implementation that does anything is UdpFile, which uses the socket library function shutdown() to terminate writes while allowing reads.

This also tweaks HttpFile::CloseWithStatus() so that it will not generate an error if the file is closed before the HTTP response is written to the download cache.

This modifies the test HttpFileTest.MultipleWrites so that the file is Flushed after each chunk. This adds test coverage for the changes introduced in PR #1201.

Fixes #1224 (missing test coverage for HttpFile::Flush)