X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fhttp.py;h=f9a08bed869e961292d6911d03b53a5639f6b0d4;hb=0374809fd2dd8e22c24efc0ce08df9ceefcf01b5;hp=0c1b3968d90ce31bfcb13fbadd4c948c22d2289a;hpb=7d24f8a6f0bb74de07c3e6d333a2948d9186be1b;p=mpd-sima.git diff --git a/sima/lib/http.py b/sima/lib/http.py index 0c1b396..f9a08be 100644 --- a/sima/lib/http.py +++ b/sima/lib/http.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2014 Jack Kaliko +# Copyright (c) 2014-2015 Jack Kaliko # Copyright (c) 2012, 2013 Eric Larson # # This program is free software: you can redistribute it and/or modify @@ -190,12 +190,6 @@ class CacheController(object): # return the original handler return False - def add_headers(self, url): - resp = self.cache.get(url) - if resp and 'etag' in resp.headers: - return {'If-None-Match': resp.headers['etag']} - return {} - def cache_response(self, request, resp): """ Algorithm for caching requests. @@ -301,16 +295,13 @@ class HttpClient: def fetch_ws(self, prepreq): """fetch from web service""" sess = Session() - resp = sess.send(prepreq, timeout=SOCKET_TIMEOUT) + settings = sess.merge_environment_settings(prepreq.url, {}, None, False, None) + resp = sess.send(prepreq, timeout=SOCKET_TIMEOUT, **settings) if resp.status_code == 304: self.stats.update(etag=self.stats.get('etag')+1) resp = self.controller.update_cached_response(prepreq, resp) elif resp.status_code != 200: raise WSHTTPError('{0.status_code}: {0.reason}'.format(resp)) - ratelimit = resp.headers.get('x-ratelimit-remaining', None) - if ratelimit and self.stats: - minrl = min(int(ratelimit), self.stats.get('minrl')) - self.stats.update(minrl=minrl) self.controller.cache_response(resp.request, resp) return resp