Closed YesThatGy closed 1 month ago
A HTTP hook itself must always respond with a 2XX status code, even if the hook instructs tusd to respond with a non-2XX status code to the client. Any other status code is interpreted as a failure to execute the hook itself. Please read https://tus.github.io/tusd/advanced-topics/hooks/#responses for more detail on the responses for HTTP hooks.
Interesting, and that makes sense. I also ran into an issue with
"RejectUpload":"true"
Quoting the "true" cause a parse error, and
and
{\"message\" => \"The upload is too big\"}
should have read
{\"message\" : \"The upload is too big\"}
This issue can be closed.
Describe the bug When a pre_create hook is rejected due to being too large, tusd responds with a generic HTTP 500 causing my tus client to report to the user that the server is broken, rather than be able to discern that the problem really exists with the client's file being too large.
To Reproduce Steps to reproduce the behavior:
HOST="https://mysite.com/api/hooks"; $PATH/tusd/tusd_linux_amd64/tusd \ -hooks-http $HOST \ -disable-download \ --upload-dir "$PATH/data/"
HTTP_CODE: 413 RESPONSE_BODY: {"HTTPResponse":{"StatusCode":413,"Body":"{\"message\" => \"The upload is too big\"}","Header":{"Content-Type":"application\/json"}},"RejectUpload":"true"}
HTTP_CODE: 507 RESPONSE BODY: {"HTTPResponse":{"StatusCode":507,"Body":"{\"message\" => \"The upload is too big\"}","Header":{"Content-Type":"application\/json"}},"RejectUpload":"true"}
2024/09/29 15:31:09.472325 level=INFO event=RequestIncoming method=POST path="" requestId="" 2024/09/29 15:31:09.474989 level=DEBUG event=HookInvocationStart type=pre-create id="" 2024/09/29 15:31:13.905467 level=ERROR event=HookInvocationError type=pre-create id="" error="unexpected response code from hook endpoint (507): {\"HTTPResponse\":{\"StatusCode\":507,\"Body\":\"{\\"message\\" => \\"The upload is too big\\"}\",\"Header\":{\"Content-Type\":\"application\/json\"}},\"RejectUpload\":\"true\"}" 2024/09/29 15:31:13.905883 level=ERROR event=InternalServerError method=POST path="" requestId="" message="unexpected response code from hook endpoint (507): {\"HTTPResponse\":{\"StatusCode\":507,\"Body\":\"{\\"message\\" => \\"The upload is too big\\"}\",\"Header\":{\"Content-Type\":\"application\/json\"}},\"RejectUpload\":\"true\"}" 2024/09/29 15:31:13.906239 level=INFO event=ResponseOutgoing method=POST path="" requestId="" status=500 body="ERR_INTERNAL_SERVER_ERROR: unexpected response code from hook endpoint (507): {\"HTTPResponse\":{\"StatusCode\":507,\"Body\":\"{\\"message\\" => \\"The upload is too big\\"}\",\"Header\":{\"Content-Type\":\"application\/json\"}},\"RejectUpload\":\"true\"}\n"
Expected behavior Tusd client should have access to HTTP codes with more information than just 500. If it's a size issue (as what I found in my case debugging a generic "Unexpected Error") then 413 or perhaps 507 would be appropriate.
Setup details Please provide following details, if applicable to your situation:
Operating System: Client: tus_client in Flutter on Android tusd server: tusd version 2.4.0 CLI on AlmaLinux9 tusd_hooks server: AlmaLinux 8, PHP 8.3
Used tusd version: [can be obtained by running
tusd -version
] 2.4.0, Linux precompiled CLI binary, runing in usermode.Used tusd data storage: [e.g. disk store, AWS S3, Google Cloud Storage] disk store, 31 GB free
Used tusd configuration: [what arguments are you using to invoke
tusd
?] HOST="https://mysite.com/api/hooks"; $PATH/tusd/tusd_linux_amd64/tusd \ -hooks-http $HOST \ -disable-download \ --upload-dir "$PATH/data/"Used tus client library: [e.g. tus-js-client, tus-java-client, TUSKit, Uppy.js] tus_client in Flutter on Android