From 17167b1c0e088000164b87ef0a02237a3ffc107c Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 9 Feb 2015 20:14:59 +0100 Subject: * mod_python port --- http/pic/.htaccess | 7 +++++-- http/pic/fetch.php | 13 ------------- http/pic/fetch.py | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) delete mode 100644 http/pic/fetch.php create mode 100644 http/pic/fetch.py (limited to 'http/pic') diff --git a/http/pic/.htaccess b/http/pic/.htaccess index 615bc19..65ceb47 100644 --- a/http/pic/.htaccess +++ b/http/pic/.htaccess @@ -1,6 +1,9 @@ +AddHandler mod_python .py +PythonHandler fetch +PythonDebug On + RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d -RewriteRule .* fetch.php [QSA,L] - +RewriteRule .* fetch.py [QSA,L] diff --git a/http/pic/fetch.php b/http/pic/fetch.php deleted file mode 100644 index 1fb94cd..0000000 --- a/http/pic/fetch.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/http/pic/fetch.py b/http/pic/fetch.py new file mode 100644 index 0000000..0cc3556 --- /dev/null +++ b/http/pic/fetch.py @@ -0,0 +1,27 @@ +# coding=utf-8 + +from mod_python import apache +import os, urllib2 + +CEZAR_URL = 'http://msc.com.pl/cezar' + +def handler(req): + orig_req = req + while True: + if orig_req.prev: + orig_req = orig_req.prev + else: + break + + remote_resource = CEZAR_URL + orig_req.uri + request = urllib2.Request(remote_resource) + request.add_header('User-Agent', orig_req.headers_in['User-Agent']) + file_name = os.path.join(os.path.dirname(__file__), remote_resource.split('/')[-1]) + try: + response = urllib2.urlopen(request) + open(file_name, 'w+').write(response.read()) + req.content_type = response.headers['Content-Type'] + req.write(open(file_name, 'r').read()) + return apache.OK + except urllib2.URLError: + return apache.HTTP_NOT_FOUND -- cgit v1.2.3