* Show server response as error message in put saver
I'd like to use this on Tiddlyhost so users can get more informative
error messages if the put save fails for whatever reason.
This would make the put saver a viable replacement for the legacy
upload saver, which is what Tiddlyhost uses currently.
I'm not sure what standard WebDAV servers do, but I would guess they
don't provide any response body for put requests, and hence this
patch would have no impact for a standard WebDAV server. (That said,
it would be a good idea to test it to make sure there aren't any
unexpected regressions for WebDAV or other put saver compatible
services.)
* Access http response status directly in put saver
There's no need to extract it from the error string created inside
tw.utils.httpRequest if we can get it directly from the xhr object.
* Add 'Save starting' notification for put saver
There are two related changes here:
1. Add a 'Save starting' notification for the put saver, similar to
the upload saver. Not sure if it was intentionally omitted for
the put saver, but it seems reasonable to have the two be
consistent.
2. Send the 'Save starting' notifications in both upload and put
save right before the actual request is sent. While testing I
noticed that the save might have failed before the "Save
starting" notification appeared which doesn't seem useful.
* Fix WebDAV by requesting new ETag conditionally
For me. this was saving only the first time and subsequently failing.
Having revised the requests, I noticed it didn't get a new ETag after saving.
Seems not all WebDAV implementations return a new ETag in PUT requests.
In my WebDAV service (WsgiDAV) - ETag is only served from a HEAD
request.
So if no ETag is found with PUT - we request one with HEAD.
This patch fixes error handling and should also work with servers that
provide ETag directly upon PUT.
* Add tweak from PMario
Remove URI encoding from PUT saver and let the browser handle it as necessary. This seems to be the normal way of doing things. We have confirmed that several WebDAV servers do not expect the file names to be double-encoded.
* putSaver: detect edit conflicts to prevent clobbering, if possible
if the server supplies an ETag, we send it back when saving, allowing
the server to detect edit conflicts and respond with 412 (cf.
https://www.w3.org/1999/04/Editing/)
caveats:
* this only kicks in after the first save, as we don't have access to
the ETag when first loading the document
* there's no recovery mechanism (e.g. resetting `this.etag` in order to
force clobbering), other than manually reloading the document
* putSaver: retrieve ETag upon initialization for clobbering protection
this addresses one of the caveats from the previous commit
(2d75cb83af) - while theoretically prone
to a race condition, it seems unlikely that saving will be triggered
before the server responds
* putSaver: simplify URI extraction
this simplifies the approach introduced in
f51f6bf774, with the purpose of removing
the fragment identifier
* putSaver: localize error message
* putSaver: switch to built-in HTTP helper
in the process, fixed ETag assignment in `#save` method (was
`this.etag`, now `self.etag`) as well as a syntax error due to a missing
closing brace
* putSaver: consolidate URI handling