开发者

how to get feedparser to send a cache-control header?

开发者 https://www.devze.com 2023-01-15 00:15 出处:网络
I\'m using python feedparser in an aggregator client that runs behind a squid proxy.I want it to send a cache-control: max-age=600 header in the request, so that we get a reasonably up-to-date respons

I'm using python feedparser in an aggregator client that runs behind a squid proxy. I want it to send a cache-control: max-age=600 header in the request, so that we get a reasonably up-to-date response. (At the moment the feeds are returned by the proxy from its cache, even days after they changed, which is reasonable based on heuristic expiry but not good enough.)

There doesn't seem to be any direct api in feedparser to do this so what's the best way? I don't really want to change the source.

update: there's a bug, 224, asking for a way to add arbitrary headers, with partial patches, but not yet merged. That's probably the cleanest way. Otherwise it seems I need to monkeypatch either urllib or feedpars开发者_C百科er. ick.


It seems to me there are two ways:

1- wait for http://code.google.com/p/feedparser/issues/detail?id=224 to be fixed. I put up a patch that lets you send extra_headers={'Cache-control': 'max-age=0'} and we'll see if they accept it.

2- monkeypatch in to urllib2 to put some extra headers on the request, which seems to be the only answer without changing feedparser.

Better answers very welcome...

update 2010-10-29 patch is now merged upstream, and waiting for a release


The semantics of the argument have changed (it's called request_headers now) but there is a new release of feedparser out that should support this use case.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号