]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/storeid_rewrite/file/storeid_file_rewrite.pl.in
10 storeid_file_rewrite - File based Store-ID helper for Squid
14 storeid_file_rewrite filepath
18 This program acts as a store_id helper program, rewriting URLs passed
19 by Squid into storage-ids that can be used to achieve better caching
20 for websites that use different URLs for the same content.
22 It takes a text file with two tab separated columns.
23 Column 1: Regular expression to match against the URL
24 Column 2: Rewrite rule to generate a Store-ID
26 ^http:\/\/[^\.]+\.dl\.sourceforge\.net\/(.*) http://dl.sourceforge.net.squid.internal/$1
28 Rewrite rules are matched in the same order as they appear in the rules file.
29 So for best performance, sort it in order of frequency of occurrence.
31 This program will automatically detect the existence of a concurrecy channel-ID and adjust appropriately.
32 It may be used with any value 0 or above for the store_id_children concurrency= parameter.
34 For more information please see http://wiki.squid-cache.org/Features/StoreID
38 my @rules; # array of [regex, replacement string]
40 die "Usage: $0 <rewrite-file>\n" unless $#ARGV == 0;
43 open RULES
, $ARGV[0] or die "Error opening $ARGV[0]: $!";
47 if (/^\s*([^\t]+?)\s*\t+\s*([^\t]+?)\s*$/) {
48 push(@rules, [qr/$1/, $2]);
50 print STDERR
"$0: Parse error in $ARGV[0] (line $.)\n";
55 # read urls from squid and do the replacement
56 URL
: while (<STDIN
>) {
65 foreach my $rule (@rules) {
66 if (my @match = /$rule->[0]/) {
69 for (my $i=1; $i<=scalar(@match); $i++) {
70 s/\$$i/$match[$i-1]/g;
72 print $channel, "OK store-id=$_\n";
76 print $channel, "ERR\n";
83 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
85 * Squid software is distributed under GPLv2+ license and includes
86 * contributions from numerous individuals and organizations.
87 * Please see the COPYING and CONTRIBUTORS files for details.
89 Copyright (C) 2013 Alan Mizrahi <alan@mizrahi.com.ve>
90 Based on code from Eliezer Croitoru <eliezer@ngtech.co.il>
92 This program is free software; you can redistribute it and/or modify
93 it under the terms of the GNU General Public License as published by
94 the Free Software Foundation; either version 2 of the License, or
95 (at your option) any later version.
97 This program is distributed in the hope that it will be useful,
98 but WITHOUT ANY WARRANTY; without even the implied warranty of
99 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100 GNU General Public License for more details.
102 You should have received a copy of the GNU General Public License
103 along with this program; if not, write to the Free Software
104 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.