Уведомления

Группа в Telegram: @pythonsu

#1 Март 21, 2009 14:34:27

crchemist
От:
Зарегистрирован: 2008-07-09
Сообщения: 379
Репутация: +  0  -
Профиль   Отправить e-mail  

python http caching proxy

не можу нагуглити якийсь кешуючий проксі написаний на пітоні, може хтось щось таке бачив? може бути навіть не програма а бібліотека. хочу звідкись видерти правила за якими сторінка кешується.



Офлайн

#2 Март 21, 2009 14:59:20

Ferroman
От:
Зарегистрирован: 2006-11-16
Сообщения: 2759
Репутация: +  1  -
Профиль   Отправить e-mail  

python http caching proxy

Офлайн

#3 Март 21, 2009 15:37:09

crchemist
От:
Зарегистрирован: 2008-07-09
Сообщения: 379
Репутация: +  0  -
Профиль   Отправить e-mail  

python http caching proxy

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



Офлайн

#4 Март 21, 2009 17:58:54

Ferroman
От:
Зарегистрирован: 2006-11-16
Сообщения: 2759
Репутация: +  1  -
Профиль   Отправить e-mail  

python http caching proxy

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)

Отредактировано (Март 21, 2009 18:02:18)

Офлайн

#5 Март 21, 2009 18:49:00

crchemist
От:
Зарегистрирован: 2008-07-09
Сообщения: 379
Репутация: +  0  -
Профиль   Отправить e-mail  

python http caching proxy

http://code.google.com/p/httplib2/ - за це дякую. здається те що потрібно



Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version