WLW+AtomPub, Part 5: ETags (optional)

14Nov07

Windows Live Writer works fine with AtomPub servers that don’t return or expect ETags. However, if ETags are returned then Writer will use them. If a conflict is detected on PUT, this dialog is shown:

image

If Yes is pressed, we retrieve the current version of the entry, overwrite the fields that are visible in Writer, and try again with the new ETag.

Here are some pitfalls to watch out for–if you’re using/requiring ETags please read these carefully!

Respect If-match: *

When sending DELETE requests, Writer includes the header If-match: * which means that as long as the entry exists, it should be deleted. (Two servers choked on this in this week’s interop session.)

Return ETags on POST if the entity is returned

When a new entry is POSTed successfully, servers have the option to include the newly created entity in the body of the response. They signal this by including a Content-Location header that is byte-for-byte identical to the Location header. If your server does this, you should also include an ETag header, the same as would be returned on a GET to the Location URI. If not, Writer will assume that the entry doesn’t have an ETag.

ETags and media resources

After POSTing an image, Writer will attempt to retrieve its ETag (the one belonging to the media resource itself, not the media link entry) by doing a HEAD against the edit-media URI. If that call returns 405 (Method Not Allowed), then Writer will attempt a GET against the same URI.

So if your server requires If-match on media resource PUTs and supports HEAD, then make sure the proper ETag is included. Or if it can’t support HEAD, then make sure that 405 is the error you’re returning.

If an attempt to PUT an uploaded image fails for any reason (for example, you don’t follow the rules in the previous paragraph) then Writer will do a POST instead. So if you’re doing this wrong, the only external symptom will be that new images get posted every time you modify (e.g. resize) an image and republish.



2 Responses to “WLW+AtomPub, Part 5: ETags (optional)”

  1. Hi,How can I edit a post by AtomPub?
    When I try to open a rent post,WLW told me that “Unable to Retrieve Post from Server. Windows Live Writer was unable to retrieve an up-to-date copy of the post from blog server.”


  1. 1 WLW+AtomPub: Introduction « whateverblog.

%d bloggers like this: