Найти - Пользователи
Полная версия: python http caching proxy
Начало » Network » python http caching proxy
1
crchemist
не можу нагуглити якийсь кешуючий проксі написаний на пітоні, може хтось щось таке бачив? може бути навіть не програма а бібліотека. хочу звідкись видерти правила за якими сторінка кешується.
Ferroman
Щось зле шукав
http://tinyurl.com/5rkaw6
http://tinyurl.com/c995d
crchemist
http://tinyurl.com/c995d - http://www.iiccmode.com/ хз шо то за сайт
http://tinyurl.com/5rkaw6 - http://www.xhaus.com/alan/python/proxies.html - я там був і переглянув більшість з тих проксі. В жодному з тих що переглянув не знайшов в сорсах хоча б якоїсь примітивної імплементації http://tools.ietf.org/html/rfc2616#section-13 і http://www.mnot.net/blog/2007/12/12/stale
Ferroman
http://tinyurl.com/c995d - http://www.iiccmode.com/ хз шо то за сайт
А, щось я не те вставив
http://xmlhack.ru/texts/06/doing-http-caching-right/doing-http-caching-right.htm

mod-cache звідси: http://www.xhaus.com/alan/python/proxies.html#amit
# A basic cache

# Saving: every time we see a page, we save it to something in /tmp/cache;

# Reusing: every time we see a request that doesn't have pragma: no-cache,
# we look in /tmp/cache for the document, and if it's there we serve that

# What to do about:

# Cache-control: private
# Cache-Control: No-Cache

# Also, watch for cookie changes

# Browser header ``pragma: no-cache'' is used both for bookmarks and
# for reload button, so how do we distinguish?? :(

from string import *
from proxy3_util import *
from proxy3_filter import *
import os

# Make sure the directory exists
try: os.mkdir('/tmp/cache')
except: pass

CONTENT = {} # URL -> content

class Cache(BufferSomeFilter):
BUFFER_LEN = 0 # We can't deal with filtering at all
page_content = None

def filter(self, s):
# Save everything that goes by
if not self.page_content:
# Insert the headers the first time through
self.page_content = [join(self.args['serverheaders'].headers,''), '\r\n']
self.page_content.append(s)

return s

def close(self):
BufferSomeFilter.close(self)

url = self.args['url']
page_content = join(self.page_content, '')
CONTENT[url]= page_content
print 'saving', url

def event_process_request(obj, site, document, request, headers):
if (find(headers.getheader('Pragma', ''), 'no-cache') < 0 and
not headers.getheader('Content-length', '') and
CONTENT.has_key(site+document)):
# We have the content, and it's not marked as "no-cache" by the browser
print 'reusing', site+document
obj.outfile.write('HTTP/1.0 200 OK\r\n')
obj.outfile.write(CONTENT[site+document])
return []

register_filter('*', 'text/html', Cache)
register_filter('*', 'text/plain', Cache)
register_filter('*', 'image/gif', Cache)
register_filter('*', 'image/jpg', Cache)
crchemist
http://code.google.com/p/httplib2/ - за це дякую. здається те що потрібно
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB