Davical同步令牌Web请求 [英] Davical Sync-Token web request

查看:120
本文介绍了Davical同步令牌Web请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试不要在这里重新发明轮子...



我在CalDav同步实现中找到了一些不错的文档



根据其网站,DaviCal为rfc6578 -从0.9.8版开始兼容(请参见此处)。



因此,我首先发送请求以获取同步令牌,如下所示:

  PROPFIND http:// my_cal_srv / user / calendar_path HTTP / 1.1 
内容类型:application / xml; charset = utf-8
<?xml version = 1.0 encoding = utf-8吗?
< d:propfind xmlns:d =’DAV:’>
< d:prop>
< d:displayname />
< d:同步令牌/>
< / d:prop>
< / d:propfind>

这将按预期返回数据:

 <?xml version = 1.0 encoding = utf-8吗? 
< multistatus xmlns = DAV:>
< response>
< href> /caldav.php/user/calendar_path/< / href>
< propstat>
< prop>
< displayname>我的日历< / displayname>
< sync-token> data:,9< / sync-token>
< / prop>
< status> HTTP / 1.1 200 OK< / status>
< / propstat>
< / response>
< / multistatus>

到目前为止,到目前为止,我有一个令牌,它是数据:,9。因此,让我们尝试从8月起进行更改,这是我在添加某些事件之前查询服务器时拥有的令牌。

 报告http:// my_cal_srv / user / calendar_path HTTP / 1.1 
内容类型:application / xml; charset = utf-8
<?xml version = 1.0 encoding = utf-8吗?
< d:sync-collection xmlns:d = DAV:>
< d:sync-token> 8< / d:sync-token>
< d:sync-level> 1< / d:sync-level>
< d:prop>
< d:getetag />
< / d:prop>
< / d:sync-collection>

答案是:

 <?xml version = 1.0 encoding = utf-8吗?> 
< multistatus xmlns = DAV:>
< response>
< href> /caldav.php/user/path/86166f9c-3e2e-4242-9a28-0f3bfb1dd67a-caldavsyncadapter.ics< / href>
< propstat>
< prop>
< getetag> 5ed2101b0c867e490dbd71d40c7071bb< / getetag>
< / prop>
< status> HTTP / 1.1 200 OK< / status>
< / propstat>
< / response>
< response>
< href> /caldav.php/user/path/cb354fab-b41d-49ad-8a4f-8d68c9090ea0.ics< / href>
< propstat>
< prop>
< getetag> 334892703f4151024e9232eab9b515a7< / getetag>
< / prop>
< status> HTTP / 1.1 200 OK< / status>
< / propstat>
< / response>
< sync-token> data:,9< / sync-token>
< / multistatus>

删除条目后(因此我获得了同步令牌10,但仍使用令牌8进行比较),我得到以下结果:

 <?xml version = 1.0 encoding = utf-8吗? 
< multistatus xmlns = DAV:>
< response>
< href> /caldav.php/user/cal_path/86166f9c-3e2e-4242-9a28-0f3bfb1dd67a-caldavsyncadapter.ics< / href>
< status> HTTP / 1.1 404找不到< / status>
< / response>
< response>
< href> /caldav.php/user/cal_path/cb354fab-b41d-49ad-8a4f-8d68c9090ea0.ics< / href>
< propstat>
< prop>
< getetag> 334892703f4151024e9232eab9b515a7< / getetag>
< / prop>
< status> HTTP / 1.1 200 OK< / status>
< / propstat>
< / response>
< sync-token> data:,10< / sync-token>
< / multistatus>

所以我在这里有些困惑,因为我真的不知道如何解释这些结果。



有人可以向我解释如何从此处提取同步信息吗?由于ICS的名称尚不清楚,因此很难弄清更改类型。



在此先感谢您的帮助……还有X-Mas!
此致,
N。

解决方案

您收到的 data:,9不会意味着您实际上可以查询 data:,8或 7等。同步令牌是不透明的,不会为您提供版本控制系统(您需要类似 DAV版本扩展插件)。



DAV同步令牌是一种简单的优化技术,仅此而已。它们对于客户端是完全不透明的,并且服务器可以随时使同步令牌过期(并且不需要保存逻辑删除等等)。例如,不能存储墓碑的服务器可以在DELETE请求上简单地使令牌过期。



您使用同步令牌的方式是:


  1. 找出父集合的哪些子集合需要重新同步

  2. 优化子资源的同步集合

1)需要同步哪些子集合



假设您有一个日历集合(例如my_cal_srv / user /),并且您对此集合执行了PROPFIND Depth:1,要求获得子集合的同步令牌。如果那些不再与您的客户端缓存匹配,您就会知道您只需要同步那些子集合。



注意:请勿使用令牌您从此请求中获得了同步子集合的要求(这是您在上面所做的)。它可能已经过期。在同步报告中,仅使用从同步报告中获得的令牌!



2)优化集合内容的同步



<再次:同步令牌是一种优化,仅此而已。您总是需要做好准备以获取(有效)valid-token前置条件错误(这意味着服务器使令牌到期)并完全重新收集集合内容!然后将其(URL,ETag)与您的缓存版本进行比较,以了解所做的更改。 (基本上,如果您的服务器不支持同步报告,则需要执行所有步骤。)



如果您在sync-中获得了同步令牌,报告结果,然后可以在下一个同步请求中使用它。如果服务器仍处于状态,则只会为您提供更改。如果令牌过期,它将给您同步令牌错误。



注意:如果不明显-在第一个同步请求中,不提供令牌。您运行不带令牌的查询,并取回所有内容。如果服务器向您发送(无效)有效同步令牌错误,请再次执行相同的操作。


I am trying not to re-invent the wheel here...

I have found some nice documentation on CalDav sync implementation there

According to its website, DaviCal is rfc6578-compliant since v. 0.9.8 (see here).

I therefore first send my request to get the sync token as follows:

PROPFIND http://my_cal_srv/user/calendar_path HTTP/1.1
Content-Type: application/xml; charset="utf-8"
    <?xml version="1.0" encoding="utf-8" ?>
      <d:propfind xmlns:d='DAV:'> 
        <d:prop>
          <d:displayname />
          <d:sync-token />
        </d:prop>
       </d:propfind>

This returns data as expected:

<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:">
 <response>
  <href>/caldav.php/user/calendar_path/</href>
  <propstat>
   <prop>
    <displayname>My Calendar</displayname>
    <sync-token>data:,9</sync-token>
   </prop>
   <status>HTTP/1.1 200 OK</status>
  </propstat>
 </response>
</multistatus>

So far so good, I have a token, it's "data: ,9". So, let's just try to get changes since 8, the token I had when I queried the server prior to adding some event.

REPORT http://my_cal_srv/user/calendar_path HTTP/1.1
Content-Type: application/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<d:sync-collection xmlns:d="DAV:">
  <d:sync-token>8</d:sync-token>
  <d:sync-level>1</d:sync-level>
  <d:prop>
    <d:getetag/>
  </d:prop>
</d:sync-collection>

The answer is:

<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:">
 <response>
  <href>/caldav.php/user/path/86166f9c-3e2e-4242-9a28-0f3bfb1dd67a-caldavsyncadapter.ics</href>
  <propstat>
   <prop>
    <getetag>"5ed2101b0c867e490dbd71d40c7071bb"</getetag>
   </prop>
   <status>HTTP/1.1 200 OK</status>
  </propstat>
 </response>
 <response>
  <href>/caldav.php/user/path/cb354fab-b41d-49ad-8a4f-8d68c9090ea0.ics</href>
  <propstat>
   <prop>
    <getetag>"334892703f4151024e9232eab9b515a7"</getetag>
   </prop>
   <status>HTTP/1.1 200 OK</status>
  </propstat>
 </response>
 <sync-token>data:,9</sync-token>
</multistatus>

After deleting an entry (so I get sync-token 10, and still compare using token 8), I get following result :

<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:">
 <response>
  <href>/caldav.php/user/cal_path/86166f9c-3e2e-4242-9a28-0f3bfb1dd67a-caldavsyncadapter.ics</href>
  <status>HTTP/1.1 404 Not Found</status>
 </response>
 <response>
  <href>/caldav.php/user/cal_path/cb354fab-b41d-49ad-8a4f-8d68c9090ea0.ics</href>
  <propstat>
   <prop>
    <getetag>"334892703f4151024e9232eab9b515a7"</getetag>
   </prop>
   <status>HTTP/1.1 200 OK</status>
  </propstat>
 </response>
 <sync-token>data:,10</sync-token>
</multistatus>

So I am a little confused here as I don't really know how to interpret these results...

Could anybody please explain to me how to extract the sync info from here? It is a little hard to figure out the changes types because the ICS namings are unclear...

Thanks in advance for helping out... And merry X-Mas ! Regards, N.

解决方案

That you get a "data:,9" doesn't imply you can actually query "data:,8" or ,7 etc. Sync tokens are opaque and do NOT give you a versioning system (you need sth like DAV Versioning Extensions for that).

DAV sync-tokens are a simple optimization technique - nothing more. They are completely opaque to the client and the server can expire sync tokens at any time (and is not required to save tombstones and such). Eg a server which can't store tombstones can simply expire tokens on DELETE requests.

The way you use sync-tokens is:

  1. to figure out which child collections of a parent collection need to be re-synced
  2. to optimize syncing of a the resources within a child collection

1) Which child collections need to be synced

Assume you have a collection of calendars (e.g. my_cal_srv/user/) and you do a PROPFIND Depth:1 on this collection, asking for the sync-tokens of the child collections. If those don't match the ones of your clients cache anymore, you know you need to perform a sync of just those child collections.

Note: do NOT use the token you got back from this request to sync the child collection (which is what you do above). It might have expired already. Within sync-reports only use tokens you got from sync-reports!

2) Optimizing syncing of the collection contents

Again: sync-token's are an optimization, nothing more. You always need to be prepared to get an (in)valid-sync-token precondition error (which means the server expired the token) and do a full refetch of the collection contents! And then compare that (URL,ETag) to your cached version to figure out what the changes are. (essentially all the steps you need to do when you have a server which doesn't support sync-reports).

If you get a sync-token in the sync-report results, you can then use it in the next sync-request. If the server still has the state, it'll just give you the changes. If it expired the token, it'll give you the sync-token error.

Note: In case it isn't obvious - in the very first sync-request you don't (can't) provide a token. You run the query w/o a token and get back all the contents. You do the same again if the server sends you an (in)valid-sync-token error.

这篇关于Davical同步令牌Web请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆