Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is in reference to this thread in the tus-js-client repository issues. @Acconut invited us to create a lightweight PR to solve this issue, on the tusd side.
PROBLEM
In GCP Cloud Run, HTTP/2 traffic is accepted but TLS is terminated at the load balancer and traffic is forwarded to the tusd container as cleartext (non-encrypted) http. This is problematic because tusd expects TLS for HTTP/2 traffic.
SOLUTION
Golang's net/http2 library allows for a drop in support of HTTP/2 in cleartext (h2c), with simultaneous capability for HTTP/1.1 cleartext. Meaning, if traffic is identified to be HTTP/1.1, the h2c handler will bypass HTTP/2 and serve based on HTTP/1.1.
This PR uses the
newHandler()
method to wrap the existingmux
handler, such that no additional configuration is needed to handle either HTTP version. HTTP/2 encrypted traffic can also be handled as usual by making calls directly to tusd via https. If behind a load balancer such as Cloud Run, all that would be required in terms of configuration is the-behind-proxy
flag.TESTING
We built an image based on this PR and tested it for file uploads on Cloud Run with tus-js-client and it performed successfully.