HandyCache форум

Главная категория => English forum => Тема начата: www от 31 мая 2011, 06:03:31



Название: [Extension] Smart HTTP Referers
Отправлено: www от 31 мая 2011, 06:03:31
I've created this simple Lua extension and hope that it'll be useful for someone else. Feel free to translate this "manual" to Russian or other languages, and please let me know if you find any errors or have any suggestions to improve the code. I'm not a programmer. :P

If a page requests a URL from another domain, Smart HTTP Referers modifies the referer to the new domain and adds the rule "SHR" to the monitor. If there's no referer or if the request comes from the same domain or a subdomain of the same domain, SHR doesn't do anything.

I was inspired by Firefox's RefControl (https://addons.mozilla.org/en-US/firefox/addon/refcontrol/) and mai62's example extension (http://handycache.ru/component/option,com_smf/Itemid,10/topic,3156.msg26582/#msg26582), and tested it by opening some websites on Opera for Windows and Firefox for Linux (with HandyCache running on Wine).

List of variables

This list is just for reference.

VariableDescription
referer_hostThe full host of the webpage that sent the GET request. Examples:
Код:
example.net
www.example.co.uk
one.more.example.net
referer_host_mainOnly the main domain of the host requesting the URL. It's created by stripping out all subdomains from referer_host_full. Examples:
Код:
example.net
example.co.uk
example.com
get_host_fullThe full host of the requested URL. Examples:
Код:
example.net
www.example.co.uk
one.more.example.net
get_host_mainOnly the main domain of the server that hosts the requested URL. It's created by stripping out all subdomains from get_host_full. Examples:
Код:
example.net
example.co.uk
example.com
new_headersThe HTTP headers that will actually be sent to the host of the requested URL, if and only if get_host_main is different from referer_host_main. It's the same as get_host_main with a slash at the end.



Название: Re: [Extension] Smart HTTP Referers
Отправлено: www от 06 июля 2011, 04:56:20
I've added mai62's example of a graphical options window (http://handycache.ru/component/option,com_smf/Itemid,10/topic,4012.0/) to STR, so users can add exceptions easily. The only website I've had problems with after a month using STR was Google, so I've included some of their domains by default to the exceptions list.


Название: Re: [Extension] Smart HTTP Referers
Отправлено: www от 07 января 2012, 13:56:35
After updating HandyCache to the latest version, I've noticed that my extension is changing the referer to

Код:
Referer: opera.com
 http://www.google.com/xhtml?hl=en&q=echo.opera.com&pws=0

instead of just

Код:
Referer: opera.com

Was it already broken or this was caused by the HandyCache update? :(


Название: Re: [Extension] Smart HTTP Referers
Отправлено: mai62 от 07 января 2012, 16:18:03
In last version the options used for regular expressions have changed.
Replace this line
  new_headers = re.replace(hc.request_header,    "Referer:.*?http\:\/\/(.*?\/).*?\r\n", "Referer: http://"..get_host_full .. "\/\r\n")
with another
  new_headers = re.replace(hc.request_header, "Referer:[^\r]*\r\n", "Referer: http://"..get_host_full)


Название: Re: [Extension] Smart HTTP Referers
Отправлено: www от 08 января 2012, 01:30:01
It seems that it worked. Thanks!