-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error uploading resource with non utf-8 bytes #137
Comments
Generally speaking TiddlyWeb takes a pretty hard line about encoding. It expects text-based content to be utf-8 encoded. There are a few different reasons for this:
Yes, was there any message in the body of the 400 response?
There's been discussion in the past about doing content negotiation for error responses and the general consensus was it wasn't worth it. In default TiddlyWeb the responses are text/plain, which seems to align okay with what you would expect when using the system mostly as an API and where the status codes are the most meaningful part of the response. Tank overrides this behavior to templatize 400 responses into HTML because that's the level at which the errors matter: when using the API. It would be possible (probably without too much difficulty) to get it to attend to the accept header but are the semantics there appropriate: Accept is used when things go well to say "I want the resource I've requested to come back as X". Does it also apply for error messages? In any case, the fact that you're getting an untrapped 500 on drag and drop is a bug, that bit of "closet" code is not being careful when making a call to decode. The expected response there would have been the 400 that you're seeing elsewhere. I'll look into fixing that and in the process see whether the 400 is getting the message it deserves. We can explore accepting other encodings if you like, but I'd rather people put their files in a reasonable encoding in the first place. What do you think? /cc @FND |
I agree with all this (UTF-8 activism, semantic ambiguity of interpreting My main issue was that the 400 response didn't say why the request was bad. Old response text: <div class="message"> </div>
<div class="extra">
You left something out of that request, perhaps go back and
try again.
</div> After 2bd6ca9: <div class="message">
unable to decode tiddler, utf-8 expected: 'utf8' codec can't decode byte 0xab in position 252830: invalid start byte
</div>
... And the DND upload is correctly throwing a 400 now. For me this issue seems resolved 🍹 WRT content negotiation for error messages, the original HTTP/1.1 RFC is fairly clear:
while the newer HTTP semantics RFC is more coy:
My feeling is that the server should return HTML errors only if the request has |
I guess to more directly address the semantics of |
That seems like a sensible argument. To me, |
So it appears the outcome of this is that it would be nice if tank only sent text/html on errors some of the time. So I've created #138 as a reminder for that. |
Example using
tank
helper script from https://gist.github.com/edrex/8aaea3f453fe46237c1ftank PUT /bags/mgsd/tiddlers/app Content-Type:'text/html' < a_file_with_non_utf8_bytes.html
Drag and drop upload through browser:
I'm not sure if there's a bug here.
Unrelated: 400s always come back as HTML. Should they respect
Accept: text/plain
?The text was updated successfully, but these errors were encountered: