rebuilt .html docs for privoxy version 3.0.26
[privoxy.git] / doc / webserver / user-manual / appendix.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3
4 <html>
5 <head>
6   <title>Appendix</title>
7   <meta name="GENERATOR" content=
8   "Modular DocBook HTML Stylesheet Version 1.79">
9   <link rel="HOME" title="Privoxy 3.0.26 User Manual" href="index.html">
10   <link rel="PREVIOUS" title="See Also" href="seealso.html">
11   <link rel="STYLESHEET" type="text/css" href="../p_doc.css">
12   <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
13   <link rel="STYLESHEET" type="text/css" href="p_doc.css">
14 </head>
15
16 <body class="SECT1" bgcolor="#EEEEEE" text="#000000" link="#0000FF" vlink=
17 "#840084" alink="#0000FF">
18   <div class="NAVHEADER">
19     <table summary="Header navigation table" width="100%" border="0"
20     cellpadding="0" cellspacing="0">
21       <tr>
22         <th colspan="3" align="center">Privoxy 3.0.26 User Manual</th>
23       </tr>
24
25       <tr>
26         <td width="10%" align="left" valign="bottom"><a href="seealso.html"
27         accesskey="P">Prev</a></td>
28
29         <td width="80%" align="center" valign="bottom"></td>
30
31         <td width="10%" align="right" valign="bottom">&nbsp;</td>
32       </tr>
33     </table>
34     <hr align="left" width="100%">
35   </div>
36
37   <div class="SECT1">
38     <h1 class="SECT1"><a name="APPENDIX" id="APPENDIX">14. Appendix</a></h1>
39
40     <div class="SECT2">
41       <h2 class="SECT2"><a name="REGEX" id="REGEX">14.1. Regular
42       Expressions</a></h2>
43
44       <p><span class="APPLICATION">Privoxy</span> uses Perl-style
45       <span class="QUOTE">"regular expressions"</span> in its <a href=
46       "actions-file.html">actions files</a> and <a href=
47       "filter-file.html">filter file</a>, through the <a href=
48       "http://www.pcre.org/" target="_top">PCRE</a> and <span class=
49       "APPLICATION">PCRS</span> libraries.</p>
50
51       <p>If you are reading this, you probably don't understand what
52       <span class="QUOTE">"regular expressions"</span> are, or what they can
53       do. So this will be a very brief introduction only. A full explanation
54       would require a <a href="http://www.oreilly.com/catalog/regex/" target=
55       "_top">book</a> ;-)</p>
56
57       <p>Regular expressions provide a language to describe patterns that can
58       be run against strings of characters (letter, numbers, etc), to see if
59       they match the string or not. The patterns are themselves (sometimes
60       complex) strings of literal characters, combined with wild-cards, and
61       other special characters, called meta-characters. The <span class=
62       "QUOTE">"meta-characters"</span> have special meanings and are used to
63       build complex patterns to be matched against. Perl Compatible Regular
64       Expressions are an especially convenient <span class=
65       "QUOTE">"dialect"</span> of the regular expression language.</p>
66
67       <p>To make a simple analogy, we do something similar when we use
68       wild-card characters when listing files with the <b class=
69       "COMMAND">dir</b> command in DOS. <tt class="LITERAL">*.*</tt> matches
70       all filenames. The <span class="QUOTE">"special"</span> character here
71       is the asterisk which matches any and all characters. We can be more
72       specific and use <tt class="LITERAL">?</tt> to match just individual
73       characters. So <span class="QUOTE">"dir file?.text"</span> would match
74       <span class="QUOTE">"file1.txt"</span>, <span class=
75       "QUOTE">"file2.txt"</span>, etc. We are pattern matching, using a
76       similar technique to <span class="QUOTE">"regular
77       expressions"</span>!</p>
78
79       <p>Regular expressions do essentially the same thing, but are much,
80       much more powerful. There are many more <span class="QUOTE">"special
81       characters"</span> and ways of building complex patterns however. Let's
82       look at a few of the common ones, and then some examples:</p>
83
84       <table border="0">
85         <tbody>
86           <tr>
87             <td><span class="emphasis"><i class="EMPHASIS">.</i></span> -
88             Matches any single character, e.g. <span class=
89             "QUOTE">"a"</span>, <span class="QUOTE">"A"</span>, <span class=
90             "QUOTE">"4"</span>, <span class="QUOTE">":"</span>, or
91             <span class="QUOTE">"@"</span>.</td>
92           </tr>
93         </tbody>
94       </table>
95
96       <table border="0">
97         <tbody>
98           <tr>
99             <td><span class="emphasis"><i class="EMPHASIS">?</i></span> - The
100             preceding character or expression is matched ZERO or ONE times.
101             Either/or.</td>
102           </tr>
103         </tbody>
104       </table>
105
106       <table border="0">
107         <tbody>
108           <tr>
109             <td><span class="emphasis"><i class="EMPHASIS">+</i></span> - The
110             preceding character or expression is matched ONE or MORE
111             times.</td>
112           </tr>
113         </tbody>
114       </table>
115
116       <table border="0">
117         <tbody>
118           <tr>
119             <td><span class="emphasis"><i class="EMPHASIS">*</i></span> - The
120             preceding character or expression is matched ZERO or MORE
121             times.</td>
122           </tr>
123         </tbody>
124       </table>
125
126       <table border="0">
127         <tbody>
128           <tr>
129             <td><span class="emphasis"><i class="EMPHASIS">\</i></span> - The
130             <span class="QUOTE">"escape"</span> character denotes that the
131             following character should be taken literally. This is used where
132             one of the special characters (e.g. <span class=
133             "QUOTE">"."</span>) needs to be taken literally and not as a
134             special meta-character. Example: <span class=
135             "QUOTE">"example\.com"</span>, makes sure the period is
136             recognized only as a period (and not expanded to its
137             meta-character meaning of any single character).</td>
138           </tr>
139         </tbody>
140       </table>
141
142       <table border="0">
143         <tbody>
144           <tr>
145             <td><span class="emphasis"><i class="EMPHASIS">[ ]</i></span> -
146             Characters enclosed in brackets will be matched if any of the
147             enclosed characters are encountered. For instance, <span class=
148             "QUOTE">"[0-9]"</span> matches any numeric digit (zero through
149             nine). As an example, we can combine this with <span class=
150             "QUOTE">"+"</span> to match any digit one of more times:
151             <span class="QUOTE">"[0-9]+"</span>.</td>
152           </tr>
153         </tbody>
154       </table>
155
156       <table border="0">
157         <tbody>
158           <tr>
159             <td><span class="emphasis"><i class="EMPHASIS">( )</i></span> -
160             parentheses are used to group a sub-expression, or multiple
161             sub-expressions.</td>
162           </tr>
163         </tbody>
164       </table>
165
166       <table border="0">
167         <tbody>
168           <tr>
169             <td><span class="emphasis"><i class="EMPHASIS">|</i></span> - The
170             <span class="QUOTE">"bar"</span> character works like an
171             <span class="QUOTE">"or"</span> conditional statement. A match is
172             successful if the sub-expression on either side of <span class=
173             "QUOTE">"|"</span> matches. As an example: <span class=
174             "QUOTE">"/(this|that) example/"</span> uses grouping and the bar
175             character and would match either <span class="QUOTE">"this
176             example"</span> or <span class="QUOTE">"that example"</span>, and
177             nothing else.</td>
178           </tr>
179         </tbody>
180       </table>
181
182       <p>These are just some of the ones you are likely to use when matching
183       URLs with <span class="APPLICATION">Privoxy</span>, and is a long way
184       from a definitive list. This is enough to get us started with a few
185       simple examples which may be more illuminating:</p>
186
187       <p><span class="emphasis"><i class="EMPHASIS"><tt class=
188       "LITERAL">/.*/banners/.*</tt></i></span> - A simple example that uses
189       the common combination of <span class="QUOTE">"."</span> and
190       <span class="QUOTE">"*"</span> to denote any character, zero or more
191       times. In other words, any string at all. So we start with a literal
192       forward slash, then our regular expression pattern (<span class=
193       "QUOTE">".*"</span>) another literal forward slash, the string
194       <span class="QUOTE">"banners"</span>, another forward slash, and lastly
195       another <span class="QUOTE">".*"</span>. We are building a directory
196       path here. This will match any file with the path that has a directory
197       named <span class="QUOTE">"banners"</span> in it. The <span class=
198       "QUOTE">".*"</span> matches any characters, and this could conceivably
199       be more forward slashes, so it might expand into a much longer looking
200       path. For example, this could match: <span class=
201       "QUOTE">"/eye/hate/spammers/banners/annoy_me_please.gif"</span>, or
202       just <span class="QUOTE">"/banners/annoying.html"</span>, or almost an
203       infinite number of other possible combinations, just so it has
204       <span class="QUOTE">"banners"</span> in the path somewhere.</p>
205
206       <p>And now something a little more complex:</p>
207
208       <p><span class="emphasis"><i class="EMPHASIS"><tt class=
209       "LITERAL">/.*/adv((er)?ts?|ertis(ing|ements?))?/</tt></i></span> - We
210       have several literal forward slashes again (<span class=
211       "QUOTE">"/"</span>), so we are building another expression that is a
212       file path statement. We have another <span class="QUOTE">".*"</span>,
213       so we are matching against any conceivable sub-path, just so it matches
214       our expression. The only true literal that <span class=
215       "emphasis"><i class="EMPHASIS">must match</i></span> our pattern is
216       <span class="APPLICATION">adv</span>, together with the forward
217       slashes. What comes after the <span class="QUOTE">"adv"</span> string
218       is the interesting part.</p>
219
220       <p>Remember the <span class="QUOTE">"?"</span> means the preceding
221       expression (either a literal character or anything grouped with
222       <span class="QUOTE">"(...)"</span> in this case) can exist or not,
223       since this means either zero or one match. So <span class=
224       "QUOTE">"((er)?ts?|ertis(ing|ements?))"</span> is optional, as are the
225       individual sub-expressions: <span class="QUOTE">"(er)"</span>,
226       <span class="QUOTE">"(ing|ements?)"</span>, and the <span class=
227       "QUOTE">"s"</span>. The <span class="QUOTE">"|"</span> means
228       <span class="QUOTE">"or"</span>. We have two of those. For instance,
229       <span class="QUOTE">"(ing|ements?)"</span>, can expand to match either
230       <span class="QUOTE">"ing"</span> <span class="emphasis"><i class=
231       "EMPHASIS">OR</i></span> <span class="QUOTE">"ements?"</span>. What is
232       being done here, is an attempt at matching as many variations of
233       <span class="QUOTE">"advertisement"</span>, and similar, as possible.
234       So this would expand to match just <span class="QUOTE">"adv"</span>, or
235       <span class="QUOTE">"advert"</span>, or <span class=
236       "QUOTE">"adverts"</span>, or <span class="QUOTE">"advertising"</span>,
237       or <span class="QUOTE">"advertisement"</span>, or <span class=
238       "QUOTE">"advertisements"</span>. You get the idea. But it would not
239       match <span class="QUOTE">"advertizements"</span> (with a <span class=
240       "QUOTE">"z"</span>). We could fix that by changing our regular
241       expression to: <span class=
242       "QUOTE">"/.*/adv((er)?ts?|erti(s|z)(ing|ements?))?/"</span>, which
243       would then match either spelling.</p>
244
245       <p><span class="emphasis"><i class="EMPHASIS"><tt class=
246       "LITERAL">/.*/advert[0-9]+\.(gif|jpe?g)</tt></i></span> - Again another
247       path statement with forward slashes. Anything in the square brackets
248       <span class="QUOTE">"[ ]"</span> can be matched. This is using
249       <span class="QUOTE">"0-9"</span> as a shorthand expression to mean any
250       digit one through nine. It is the same as saying <span class=
251       "QUOTE">"0123456789"</span>. So any digit matches. The <span class=
252       "QUOTE">"+"</span> means one or more of the preceding expression must
253       be included. The preceding expression here is what is in the square
254       brackets -- in this case, any digit one through nine. Then, at the end,
255       we have a grouping: <span class="QUOTE">"(gif|jpe?g)"</span>. This
256       includes a <span class="QUOTE">"|"</span>, so this needs to match the
257       expression on either side of that bar character also. A simple
258       <span class="QUOTE">"gif"</span> on one side, and the other side will
259       in turn match either <span class="QUOTE">"jpeg"</span> or <span class=
260       "QUOTE">"jpg"</span>, since the <span class="QUOTE">"?"</span> means
261       the letter <span class="QUOTE">"e"</span> is optional and can be
262       matched once or not at all. So we are building an expression here to
263       match image GIF or JPEG type image file. It must include the literal
264       string <span class="QUOTE">"advert"</span>, then one or more digits,
265       and a <span class="QUOTE">"."</span> (which is now a literal, and not a
266       special character, since it is escaped with <span class=
267       "QUOTE">"\"</span>), and lastly either <span class=
268       "QUOTE">"gif"</span>, or <span class="QUOTE">"jpeg"</span>, or
269       <span class="QUOTE">"jpg"</span>. Some possible matches would include:
270       <span class="QUOTE">"//advert1.jpg"</span>, <span class=
271       "QUOTE">"/nasty/ads/advert1234.gif"</span>, <span class=
272       "QUOTE">"/banners/from/hell/advert99.jpg"</span>. It would not match
273       <span class="QUOTE">"advert1.gif"</span> (no leading slash), or
274       <span class="QUOTE">"/adverts232.jpg"</span> (the expression does not
275       include an <span class="QUOTE">"s"</span>), or <span class=
276       "QUOTE">"/advert1.jsp"</span> (<span class="QUOTE">"jsp"</span> is not
277       in the expression anywhere).</p>
278
279       <p>We are barely scratching the surface of regular expressions here so
280       that you can understand the default <span class=
281       "APPLICATION">Privoxy</span> configuration files, and maybe use this
282       knowledge to customize your own installation. There is much, much more
283       that can be done with regular expressions. Now that you know enough to
284       get started, you can learn more on your own :/</p>
285
286       <p>More reading on Perl Compatible Regular expressions: <a href=
287       "http://perldoc.perl.org/perlre.html" target=
288       "_top">http://perldoc.perl.org/perlre.html</a></p>
289
290       <p>For information on regular expression based substitutions and their
291       applications in filters, please see the <a href=
292       "filter-file.html">filter file tutorial</a> in this manual.</p>
293     </div>
294
295     <div class="SECT2">
296       <h2 class="SECT2"><a name="INTERNAL-PAGES" id="INTERNAL-PAGES">14.2.
297       Privoxy's Internal Pages</a></h2>
298
299       <p>Since <span class="APPLICATION">Privoxy</span> proxies each
300       requested web page, it is easy for <span class=
301       "APPLICATION">Privoxy</span> to trap certain special URLs. In this way,
302       we can talk directly to <span class="APPLICATION">Privoxy</span>, and
303       see how it is configured, see how our rules are being applied, change
304       these rules and other configuration options, and even turn <span class=
305       "APPLICATION">Privoxy's</span> filtering off, all with a web
306       browser.</p>
307
308       <p>The URLs listed below are the special ones that allow direct access
309       to <span class="APPLICATION">Privoxy</span>. Of course, <span class=
310       "APPLICATION">Privoxy</span> must be running to access these. If not,
311       you will get a friendly error message. Internet access is not necessary
312       either.</p>
313
314       <ul>
315         <li>
316           <p>Privoxy main page:</p><a name="AEN5966" id="AEN5966"></a>
317
318           <blockquote class="BLOCKQUOTE">
319             <p><a href="http://config.privoxy.org/" target=
320             "_top">http://config.privoxy.org/</a></p>
321           </blockquote>
322
323           <p>There is a shortcut: <a href="http://p.p/" target=
324           "_top">http://p.p/</a> (But it doesn't provide a fall-back to a
325           real page, in case the request is not sent through <span class=
326           "APPLICATION">Privoxy</span>)</p>
327         </li>
328
329         <li>
330           <p>Show information about the current configuration, including
331           viewing and editing of actions files:</p><a name="AEN5974" id=
332           "AEN5974"></a>
333
334           <blockquote class="BLOCKQUOTE">
335             <p><a href="http://config.privoxy.org/show-status" target=
336             "_top">http://config.privoxy.org/show-status</a></p>
337           </blockquote>
338         </li>
339
340         <li>
341           <p>Show the source code version numbers:</p><a name="AEN5979" id=
342           "AEN5979"></a>
343
344           <blockquote class="BLOCKQUOTE">
345             <p><a href="http://config.privoxy.org/show-version" target=
346             "_top">http://config.privoxy.org/show-version</a></p>
347           </blockquote>
348         </li>
349
350         <li>
351           <p>Show the browser's request headers:</p><a name="AEN5984" id=
352           "AEN5984"></a>
353
354           <blockquote class="BLOCKQUOTE">
355             <p><a href="http://config.privoxy.org/show-request" target=
356             "_top">http://config.privoxy.org/show-request</a></p>
357           </blockquote>
358         </li>
359
360         <li>
361           <p>Show which actions apply to a URL and why:</p><a name="AEN5989"
362           id="AEN5989"></a>
363
364           <blockquote class="BLOCKQUOTE">
365             <p><a href="http://config.privoxy.org/show-url-info" target=
366             "_top">http://config.privoxy.org/show-url-info</a></p>
367           </blockquote>
368         </li>
369
370         <li>
371           <p>Toggle Privoxy on or off. This feature can be turned off/on in
372           the main <tt class="FILENAME">config</tt> file. When toggled
373           <span class="QUOTE">"off"</span>, <span class=
374           "QUOTE">"Privoxy"</span> continues to run, but only as a
375           pass-through proxy, with no actions taking place:</p><a name=
376           "AEN5997" id="AEN5997"></a>
377
378           <blockquote class="BLOCKQUOTE">
379             <p><a href="http://config.privoxy.org/toggle" target=
380             "_top">http://config.privoxy.org/toggle</a></p>
381           </blockquote>
382
383           <p>Short cuts. Turn off, then on:</p><a name="AEN6001" id=
384           "AEN6001"></a>
385
386           <blockquote class="BLOCKQUOTE">
387             <p><a href="http://config.privoxy.org/toggle?set=disable" target=
388             "_top">http://config.privoxy.org/toggle?set=disable</a></p>
389           </blockquote><a name="AEN6004" id="AEN6004"></a>
390
391           <blockquote class="BLOCKQUOTE">
392             <p><a href="http://config.privoxy.org/toggle?set=enable" target=
393             "_top">http://config.privoxy.org/toggle?set=enable</a></p>
394           </blockquote>
395         </li>
396       </ul>
397     </div>
398
399     <div class="SECT2">
400       <h2 class="SECT2"><a name="CHAIN" id="CHAIN">14.3. Chain of
401       Events</a></h2>
402
403       <p>Let's take a quick look at how some of <span class=
404       "APPLICATION">Privoxy's</span> core features are triggered, and the
405       ensuing sequence of events when a web page is requested by your
406       browser:</p>
407
408       <ul>
409         <li>
410           <p>First, your web browser requests a web page. The browser knows
411           to send the request to <span class="APPLICATION">Privoxy</span>,
412           which will in turn, relay the request to the remote web server
413           after passing the following tests:</p>
414         </li>
415
416         <li>
417           <p><span class="APPLICATION">Privoxy</span> traps any request for
418           its own internal CGI pages (e.g <a href="http://p.p/" target=
419           "_top">http://p.p/</a>) and sends the CGI page back to the
420           browser.</p>
421         </li>
422
423         <li>
424           <p>Next, <span class="APPLICATION">Privoxy</span> checks to see if
425           the URL matches any <a href="actions-file.html#BLOCK"><span class=
426           "QUOTE">"+block"</span></a> patterns. If so, the URL is then
427           blocked, and the remote web server will not be contacted. <a href=
428           "actions-file.html#HANDLE-AS-IMAGE"><span class=
429           "QUOTE">"+handle-as-image"</span></a> and <a href=
430           "actions-file.html#HANDLE-AS-EMPTY-DOCUMENT"><span class=
431           "QUOTE">"+handle-as-empty-document"</span></a> are then checked,
432           and if there is no match, an HTML <span class=
433           "QUOTE">"BLOCKED"</span> page is sent back to the browser.
434           Otherwise, if it does match, an image is returned for the former,
435           and an empty text document for the latter. The type of image would
436           depend on the setting of <a href=
437           "actions-file.html#SET-IMAGE-BLOCKER"><span class=
438           "QUOTE">"+set-image-blocker"</span></a> (blank, checkerboard
439           pattern, or an HTTP redirect to an image elsewhere).</p>
440         </li>
441
442         <li>
443           <p>Untrusted URLs are blocked. If URLs are being added to the
444           <tt class="FILENAME">trust</tt> file, then that is done.</p>
445         </li>
446
447         <li>
448           <p>If the URL pattern matches the <a href=
449           "actions-file.html#FAST-REDIRECTS"><span class=
450           "QUOTE">"+fast-redirects"</span></a> action, it is then processed.
451           Unwanted parts of the requested URL are stripped.</p>
452         </li>
453
454         <li>
455           <p>Now the rest of the client browser's request headers are
456           processed. If any of these match any of the relevant actions (e.g.
457           <a href="actions-file.html#HIDE-USER-AGENT"><span class=
458           "QUOTE">"+hide-user-agent"</span></a>, etc.), headers are
459           suppressed or forged as determined by these actions and their
460           parameters.</p>
461         </li>
462
463         <li>
464           <p>Now the web server starts sending its response back (i.e.
465           typically a web page).</p>
466         </li>
467
468         <li>
469           <p>First, the server headers are read and processed to determine,
470           among other things, the MIME type (document type) and encoding. The
471           headers are then filtered as determined by the <a href=
472           "actions-file.html#CRUNCH-INCOMING-COOKIES"><span class=
473           "QUOTE">"+crunch-incoming-cookies"</span></a>, <a href=
474           "actions-file.html#SESSION-COOKIES-ONLY"><span class=
475           "QUOTE">"+session-cookies-only"</span></a>, and <a href=
476           "actions-file.html#DOWNGRADE-HTTP-VERSION"><span class=
477           "QUOTE">"+downgrade-http-version"</span></a> actions.</p>
478         </li>
479
480         <li>
481           <p>If any <a href="actions-file.html#FILTER"><span class=
482           "QUOTE">"+filter"</span></a> action or <a href=
483           "actions-file.html#DEANIMATE-GIFS"><span class=
484           "QUOTE">"+deanimate-gifs"</span></a> action applies (and the
485           document type fits the action), the rest of the page is read into
486           memory (up to a configurable limit). Then the filter rules (from
487           <tt class="FILENAME">default.filter</tt> and any other filter
488           files) are processed against the buffered content. Filters are
489           applied in the order they are specified in one of the filter files.
490           Animated GIFs, if present, are reduced to either the first or last
491           frame, depending on the action setting.The entire page, which is
492           now filtered, is then sent by <span class=
493           "APPLICATION">Privoxy</span> back to your browser.</p>
494
495           <p>If neither a <a href="actions-file.html#FILTER"><span class=
496           "QUOTE">"+filter"</span></a> action or <a href=
497           "actions-file.html#DEANIMATE-GIFS"><span class=
498           "QUOTE">"+deanimate-gifs"</span></a> matches, then <span class=
499           "APPLICATION">Privoxy</span> passes the raw data through to the
500           client browser as it becomes available.</p>
501         </li>
502
503         <li>
504           <p>As the browser receives the now (possibly filtered) page
505           content, it reads and then requests any URLs that may be embedded
506           within the page source, e.g. ad images, stylesheets, JavaScript,
507           other HTML documents (e.g. frames), sounds, etc. For each of these
508           objects, the browser issues a separate request (this is easily
509           viewable in <span class="APPLICATION">Privoxy's</span> logs). And
510           each such request is in turn processed just as above. Note that a
511           complex web page will have many, many such embedded URLs. If these
512           secondary requests are to a different server, then quite possibly a
513           very differing set of actions is triggered.</p>
514         </li>
515       </ul>
516
517       <p>NOTE: This is somewhat of a simplistic overview of what happens with
518       each URL request. For the sake of brevity and simplicity, we have
519       focused on <span class="APPLICATION">Privoxy's</span> core features
520       only.</p>
521     </div>
522
523     <div class="SECT2">
524       <h2 class="SECT2"><a name="ACTIONSANAT" id="ACTIONSANAT">14.4.
525       Troubleshooting: Anatomy of an Action</a></h2>
526
527       <p>The way <span class="APPLICATION">Privoxy</span> applies <a href=
528       "actions-file.html#ACTIONS">actions</a> and <a href=
529       "actions-file.html#FILTER">filters</a> to any given URL can be complex,
530       and not always so easy to understand what is happening. And sometimes
531       we need to be able to <span class="emphasis"><i class=
532       "EMPHASIS">see</i></span> just what <span class=
533       "APPLICATION">Privoxy</span> is doing. Especially, if something
534       <span class="APPLICATION">Privoxy</span> is doing is causing us a
535       problem inadvertently. It can be a little daunting to look at the
536       actions and filters files themselves, since they tend to be filled with
537       <a href="appendix.html#REGEX">regular expressions</a> whose
538       consequences are not always so obvious.</p>
539
540       <p>One quick test to see if <span class="APPLICATION">Privoxy</span> is
541       causing a problem or not, is to disable it temporarily. This should be
542       the first troubleshooting step (be sure to flush caches afterward!).
543       Looking at the logs is a good idea too. (Note that both the toggle
544       feature and logging are enabled via <tt class="FILENAME">config</tt>
545       file settings, and may need to be turned <span class=
546       "QUOTE">"on"</span>.)</p>
547
548       <p>Another easy troubleshooting step to try is if you have done any
549       customization of your installation, revert back to the installed
550       defaults and see if that helps. There are times the developers get
551       complaints about one thing or another, and the problem is more related
552       to a customized configuration issue.</p>
553
554       <p><span class="APPLICATION">Privoxy</span> also provides the <a href=
555       "http://config.privoxy.org/show-url-info" target=
556       "_top">http://config.privoxy.org/show-url-info</a> page that can show
557       us very specifically how <span class="APPLICATION">actions</span> are
558       being applied to any given URL. This is a big help for
559       troubleshooting.</p>
560
561       <p>First, enter one URL (or partial URL) at the prompt, and then
562       <span class="APPLICATION">Privoxy</span> will tell us how the current
563       configuration will handle it. This will not help with filtering effects
564       (i.e. the <a href="actions-file.html#FILTER"><span class=
565       "QUOTE">"+filter"</span></a> action) from one of the filter files since
566       this is handled very differently and not so easy to trap! It also will
567       not tell you about any other URLs that may be embedded within the URL
568       you are testing. For instance, images such as ads are expressed as URLs
569       within the raw page source of HTML pages. So you will only get info for
570       the actual URL that is pasted into the prompt area -- not any sub-URLs.
571       If you want to know about embedded URLs like ads, you will have to dig
572       those out of the HTML source. Use your browser's <span class=
573       "QUOTE">"View Page Source"</span> option for this. Or right click on
574       the ad, and grab the URL.</p>
575
576       <p>Let's try an example, <a href="http://google.com" target=
577       "_top">google.com</a>, and look at it one section at a time in a sample
578       configuration (your real configuration may vary):</p>
579
580       <table border="0" bgcolor="#E0E0E0" width="100%">
581         <tr>
582           <td>
583             <pre class="SCREEN">
584  Matches for http://www.google.com:
585
586  In file: default.action <span class="GUIBUTTON">[ View ]</span> <span class=
587 "GUIBUTTON">[ Edit ]</span>
588
589  {+change-x-forwarded-for{block}
590  +deanimate-gifs {last}
591  +fast-redirects {check-decoded-url}
592  +filter {refresh-tags}
593  +filter {img-reorder}
594  +filter {banners-by-size}
595  +filter {webbugs}
596  +filter {jumping-windows}
597  +filter {ie-exploits}
598  +hide-from-header {block}
599  +hide-referrer {forge}
600  +session-cookies-only
601  +set-image-blocker {pattern}
602 /
603
604  { -session-cookies-only }
605  .google.com
606
607  { -fast-redirects }
608  .google.com
609
610 In file: user.action <span class="GUIBUTTON">[ View ]</span> <span class=
611 "GUIBUTTON">[ Edit ]</span>
612 (no matches in this file)
613 </pre>
614           </td>
615         </tr>
616       </table>
617
618       <p>This is telling us how we have defined our <a href=
619       "actions-file.html#ACTIONS"><span class="QUOTE">"actions"</span></a>,
620       and which ones match for our test case, <span class=
621       "QUOTE">"google.com"</span>. Displayed is all the actions that are
622       available to us. Remember, the <tt class="LITERAL">+</tt> sign denotes
623       <span class="QUOTE">"on"</span>. <tt class="LITERAL">-</tt> denotes
624       <span class="QUOTE">"off"</span>. So some are <span class=
625       "QUOTE">"on"</span> here, but many are <span class=
626       "QUOTE">"off"</span>. Each example we try may provide a slightly
627       different end result, depending on our configuration directives.</p>
628
629       <p>The first listing is for our <tt class=
630       "FILENAME">default.action</tt> file. The large, multi-line listing, is
631       how the actions are set to match for all URLs, i.e. our default
632       settings. If you look at your <span class="QUOTE">"actions"</span>
633       file, this would be the section just below the <span class=
634       "QUOTE">"aliases"</span> section near the top. This will apply to all
635       URLs as signified by the single forward slash at the end of the listing
636       -- <span class="QUOTE">" / "</span>.</p>
637
638       <p>But we have defined additional actions that would be exceptions to
639       these general rules, and then we list specific URLs (or patterns) that
640       these exceptions would apply to. Last match wins. Just below this then
641       are two explicit matches for <span class="QUOTE">".google.com"</span>.
642       The first is negating our previous cookie setting, which was for
643       <a href="actions-file.html#SESSION-COOKIES-ONLY"><span class=
644       "QUOTE">"+session-cookies-only"</span></a> (i.e. not persistent). So we
645       will allow persistent cookies for google, at least that is how it is in
646       this example. The second turns <span class="emphasis"><i class=
647       "EMPHASIS">off</i></span> any <a href=
648       "actions-file.html#FAST-REDIRECTS"><span class=
649       "QUOTE">"+fast-redirects"</span></a> action, allowing this to take
650       place unmolested. Note that there is a leading dot here -- <span class=
651       "QUOTE">".google.com"</span>. This will match any hosts and
652       sub-domains, in the google.com domain also, such as <span class=
653       "QUOTE">"www.google.com"</span> or <span class=
654       "QUOTE">"mail.google.com"</span>. But it would not match <span class=
655       "QUOTE">"www.google.de"</span>! So, apparently, we have these two
656       actions defined as exceptions to the general rules at the top somewhere
657       in the lower part of our <tt class="FILENAME">default.action</tt> file,
658       and <span class="QUOTE">"google.com"</span> is referenced somewhere in
659       these latter sections.</p>
660
661       <p>Then, for our <tt class="FILENAME">user.action</tt> file, we again
662       have no hits. So there is nothing google-specific that we might have
663       added to our own, local configuration. If there was, those actions
664       would over-rule any actions from previously processed files, such as
665       <tt class="FILENAME">default.action</tt>. <tt class=
666       "FILENAME">user.action</tt> typically has the last word. This is the
667       best place to put hard and fast exceptions,</p>
668
669       <p>And finally we pull it all together in the bottom section and
670       summarize how <span class="APPLICATION">Privoxy</span> is applying all
671       its <span class="QUOTE">"actions"</span> to <span class=
672       "QUOTE">"google.com"</span>:</p>
673
674       <table border="0" bgcolor="#E0E0E0" width="100%">
675         <tr>
676           <td>
677             <pre class="SCREEN">
678 &#13; Final results:
679
680  -add-header
681  -block
682  +change-x-forwarded-for{block}
683  -client-header-filter{hide-tor-exit-notation}
684  -content-type-overwrite
685  -crunch-client-header
686  -crunch-if-none-match
687  -crunch-incoming-cookies
688  -crunch-outgoing-cookies
689  -crunch-server-header
690  +deanimate-gifs {last}
691  -downgrade-http-version
692  -fast-redirects
693  -filter {js-events}
694  -filter {content-cookies}
695  -filter {all-popups}
696  -filter {banners-by-link}
697  -filter {tiny-textforms}
698  -filter {frameset-borders}
699  -filter {demoronizer}
700  -filter {shockwave-flash}
701  -filter {quicktime-kioskmode}
702  -filter {fun}
703  -filter {crude-parental}
704  -filter {site-specifics}
705  -filter {js-annoyances}
706  -filter {html-annoyances}
707  +filter {refresh-tags}
708  -filter {unsolicited-popups}
709  +filter {img-reorder}
710  +filter {banners-by-size}
711  +filter {webbugs}
712  +filter {jumping-windows}
713  +filter {ie-exploits}
714  -filter {google}
715  -filter {yahoo}
716  -filter {msn}
717  -filter {blogspot}
718  -filter {no-ping}
719  -force-text-mode
720  -handle-as-empty-document
721  -handle-as-image
722  -hide-accept-language
723  -hide-content-disposition
724  +hide-from-header {block}
725  -hide-if-modified-since
726  +hide-referrer {forge}
727  -hide-user-agent
728  -limit-connect
729  -overwrite-last-modified
730  -prevent-compression
731  -redirect
732  -server-header-filter{xml-to-html}
733  -server-header-filter{html-to-xml}
734  -session-cookies-only
735  +set-image-blocker {pattern}
736 </pre>
737           </td>
738         </tr>
739       </table>
740
741       <p>Notice the only difference here to the previous listing, is to
742       <span class="QUOTE">"fast-redirects"</span> and <span class=
743       "QUOTE">"session-cookies-only"</span>, which are activated specifically
744       for this site in our configuration, and thus show in the <span class=
745       "QUOTE">"Final Results"</span>.</p>
746
747       <p>Now another example, <span class=
748       "QUOTE">"ad.doubleclick.net"</span>:</p>
749
750       <table border="0" bgcolor="#E0E0E0" width="100%">
751         <tr>
752           <td>
753             <pre class="SCREEN">
754 &#13; { +block{Domains starts with "ad"} }
755   ad*.
756
757  { +block{Domain contains "ad"} }
758   .ad.
759
760  { +block{Doubleclick banner server} +handle-as-image }
761   .[a-vx-z]*.doubleclick.net
762 </pre>
763           </td>
764         </tr>
765       </table>
766
767       <p>We'll just show the interesting part here - the explicit matches. It
768       is matched three different times. Two <span class=
769       "QUOTE">"+block{}"</span> sections, and a <span class="QUOTE">"+block{}
770       +handle-as-image"</span>, which is the expanded form of one of our
771       aliases that had been defined as: <span class=
772       "QUOTE">"+block-as-image"</span>. (<a href=
773       "actions-file.html#ALIASES"><span class="QUOTE">"Aliases"</span></a>
774       are defined in the first section of the actions file and typically used
775       to combine more than one action.)</p>
776
777       <p>Any one of these would have done the trick and blocked this as an
778       unwanted image. This is unnecessarily redundant since the last case
779       effectively would also cover the first. No point in taking chances with
780       these guys though ;-) Note that if you want an ad or obnoxious URL to
781       be invisible, it should be defined as <span class=
782       "QUOTE">"ad.doubleclick.net"</span> is done here -- as both a <a href=
783       "actions-file.html#BLOCK"><span class="QUOTE">"+block{}"</span></a>
784       <span class="emphasis"><i class="EMPHASIS">and</i></span> an <a href=
785       "actions-file.html#HANDLE-AS-IMAGE"><span class=
786       "QUOTE">"+handle-as-image"</span></a>. The custom alias <span class=
787       "QUOTE">"<tt class="LITERAL">+block-as-image</tt>"</span> just
788       simplifies the process and make it more readable.</p>
789
790       <p>One last example. Let's try <span class=
791       "QUOTE">"http://www.example.net/adsl/HOWTO/"</span>. This one is giving
792       us problems. We are getting a blank page. Hmmm ...</p>
793
794       <table border="0" bgcolor="#E0E0E0" width="100%">
795         <tr>
796           <td>
797             <pre class="SCREEN">
798 &#13; Matches for http://www.example.net/adsl/HOWTO/:
799
800  In file: default.action <span class="GUIBUTTON">[ View ]</span> <span class=
801 "GUIBUTTON">[ Edit ]</span>
802
803  {-add-header
804   -block
805   +change-x-forwarded-for{block}
806   -client-header-filter{hide-tor-exit-notation}
807   -content-type-overwrite
808   -crunch-client-header
809   -crunch-if-none-match
810   -crunch-incoming-cookies
811   -crunch-outgoing-cookies
812   -crunch-server-header
813   +deanimate-gifs
814   -downgrade-http-version
815   +fast-redirects {check-decoded-url}
816   -filter {js-events}
817   -filter {content-cookies}
818   -filter {all-popups}
819   -filter {banners-by-link}
820   -filter {tiny-textforms}
821   -filter {frameset-borders}
822   -filter {demoronizer}
823   -filter {shockwave-flash}
824   -filter {quicktime-kioskmode}
825   -filter {fun}
826   -filter {crude-parental}
827   -filter {site-specifics}
828   -filter {js-annoyances}
829   -filter {html-annoyances}
830   +filter {refresh-tags}
831   -filter {unsolicited-popups}
832   +filter {img-reorder}
833   +filter {banners-by-size}
834   +filter {webbugs}
835   +filter {jumping-windows}
836   +filter {ie-exploits}
837   -filter {google}
838   -filter {yahoo}
839   -filter {msn}
840   -filter {blogspot}
841   -filter {no-ping}
842   -force-text-mode
843   -handle-as-empty-document
844   -handle-as-image
845   -hide-accept-language
846   -hide-content-disposition
847   +hide-from-header{block}
848   +hide-referer{forge}
849   -hide-user-agent
850   -overwrite-last-modified
851   +prevent-compression
852   -redirect
853   -server-header-filter{xml-to-html}
854   -server-header-filter{html-to-xml}
855   +session-cookies-only
856   +set-image-blocker{blank} }
857    /
858
859  { +block{Path contains "ads".} +handle-as-image }
860   /ads
861 </pre>
862           </td>
863         </tr>
864       </table>
865
866       <p>Ooops, the <span class="QUOTE">"/adsl/"</span> is matching
867       <span class="QUOTE">"/ads"</span> in our configuration! But we did not
868       want this at all! Now we see why we get the blank page. It is actually
869       triggering two different actions here, and the effects are aggregated
870       so that the URL is blocked, and <span class=
871       "APPLICATION">Privoxy</span> is told to treat the block as if it were
872       an image. But this is, of course, all wrong. We could now add a new
873       action below this (or better in our own <tt class=
874       "FILENAME">user.action</tt> file) that explicitly <span class=
875       "emphasis"><i class="EMPHASIS">un</i></span> blocks ( <a href=
876       "actions-file.html#BLOCK"><span class="QUOTE">"{-block}"</span></a>)
877       paths with <span class="QUOTE">"adsl"</span> in them (remember, last
878       match in the configuration wins). There are various ways to handle such
879       exceptions. Example:</p>
880
881       <table border="0" bgcolor="#E0E0E0" width="100%">
882         <tr>
883           <td>
884             <pre class="SCREEN">
885 &#13; { -block }
886   /adsl
887 </pre>
888           </td>
889         </tr>
890       </table>
891
892       <p>Now the page displays ;-) Remember to flush your browser's caches
893       when making these kinds of changes to your configuration to insure that
894       you get a freshly delivered page! Or, try using <tt class=
895       "LITERAL">Shift+Reload</tt>.</p>
896
897       <p>But now what about a situation where we get no explicit matches like
898       we did with:</p>
899
900       <table border="0" bgcolor="#E0E0E0" width="100%">
901         <tr>
902           <td>
903             <pre class="SCREEN">
904 &#13; { +block{Path starts with "ads".} +handle-as-image }
905  /ads
906 </pre>
907           </td>
908         </tr>
909       </table>
910
911       <p>That actually was very helpful and pointed us quickly to where the
912       problem was. If you don't get this kind of match, then it means one of
913       the default rules in the first section of <tt class=
914       "FILENAME">default.action</tt> is causing the problem. This would
915       require some guesswork, and maybe a little trial and error to isolate
916       the offending rule. One likely cause would be one of the <a href=
917       "actions-file.html#FILTER"><span class="QUOTE">"+filter"</span></a>
918       actions. These tend to be harder to troubleshoot. Try adding the URL
919       for the site to one of aliases that turn off <a href=
920       "actions-file.html#FILTER"><span class=
921       "QUOTE">"+filter"</span></a>:</p>
922
923       <table border="0" bgcolor="#E0E0E0" width="100%">
924         <tr>
925           <td>
926             <pre class="SCREEN">
927 &#13; { shop }
928  .quietpc.com
929  .worldpay.com   # for quietpc.com
930  .jungle.com
931  .scan.co.uk
932  .forbes.com
933 </pre>
934           </td>
935         </tr>
936       </table>
937
938       <p><span class="QUOTE">"<tt class="LITERAL">{ shop }</tt>"</span> is an
939       <span class="QUOTE">"alias"</span> that expands to <span class=
940       "QUOTE">"<tt class="LITERAL">{ -filter -session-cookies-only
941       }</tt>"</span>. Or you could do your own exception to negate
942       filtering:</p>
943
944       <table border="0" bgcolor="#E0E0E0" width="100%">
945         <tr>
946           <td>
947             <pre class="SCREEN">
948 &#13; { -filter }
949  # Disable ALL filter actions for sites in this section
950  .forbes.com
951  developer.ibm.com
952  localhost
953 </pre>
954           </td>
955         </tr>
956       </table>
957
958       <p>This would turn off all filtering for these sites. This is best put
959       in <tt class="FILENAME">user.action</tt>, for local site exceptions.
960       Note that when a simple domain pattern is used by itself (without the
961       subsequent path portion), all sub-pages within that domain are included
962       automatically in the scope of the action.</p>
963
964       <p>Images that are inexplicably being blocked, may well be hitting the
965       <a href="actions-file.html#FILTER-BANNERS-BY-SIZE"><span class=
966       "QUOTE">"+filter{banners-by-size}"</span></a> rule, which assumes that
967       images of certain sizes are ad banners (works well <span class=
968       "emphasis"><i class="EMPHASIS">most of the time</i></span> since these
969       tend to be standardized).</p>
970
971       <p><span class="QUOTE">"<tt class="LITERAL">{ fragile }</tt>"</span> is
972       an alias that disables most actions that are the most likely to cause
973       trouble. This can be used as a last resort for problem sites.</p>
974
975       <table border="0" bgcolor="#E0E0E0" width="100%">
976         <tr>
977           <td>
978             <pre class="SCREEN">
979 &#13; { fragile }
980  # Handle with care: easy to break
981  mail.google.
982  mybank.example.com
983 </pre>
984           </td>
985         </tr>
986       </table>
987
988       <p><span class="emphasis"><i class="EMPHASIS">Remember to flush
989       caches!</i></span> Note that the <tt class="LITERAL">mail.google</tt>
990       reference lacks the TLD portion (e.g. <span class=
991       "QUOTE">".com"</span>). This will effectively match any TLD with
992       <tt class="LITERAL">google</tt> in it, such as <tt class=
993       "LITERAL">mail.google.de.</tt>, just as an example.</p>
994
995       <p>If this still does not work, you will have to go through the
996       remaining actions one by one to find which one(s) is causing the
997       problem.</p>
998     </div>
999   </div>
1000
1001   <div class="NAVFOOTER">
1002     <hr align="left" width="100%">
1003
1004     <table summary="Footer navigation table" width="100%" border="0"
1005     cellpadding="0" cellspacing="0">
1006       <tr>
1007         <td width="33%" align="left" valign="top"><a href="seealso.html"
1008         accesskey="P">Prev</a></td>
1009
1010         <td width="34%" align="center" valign="top"><a href="index.html"
1011         accesskey="H">Home</a></td>
1012
1013         <td width="33%" align="right" valign="top">&nbsp;</td>
1014       </tr>
1015
1016       <tr>
1017         <td width="33%" align="left" valign="top">See Also</td>
1018
1019         <td width="34%" align="center" valign="top">&nbsp;</td>
1020
1021         <td width="33%" align="right" valign="top">&nbsp;</td>
1022       </tr>
1023     </table>
1024   </div>
1025 </body>
1026 </html>