22b40dca1d6d3919b8a51acfed9e0ff6edef556b
[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.22 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.22 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="AEN6039" id="AEN6039">14.2. Privoxy's
297       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="AEN6053" id="AEN6053"></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="AEN6061" id=
332           "AEN6061"></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="AEN6066" id=
342           "AEN6066"></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="AEN6071" id=
352           "AEN6071"></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="AEN6076"
362           id="AEN6076"></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           "AEN6084" id="AEN6084"></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="AEN6088" id=
384           "AEN6088"></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="AEN6091" id="AEN6091"></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
398       <p>These may be bookmarked for quick reference. See next.</p>
399
400       <div class="SECT3">
401         <h3 class="SECT3"><a name="BOOKMARKLETS" id="BOOKMARKLETS">14.2.1.
402         Bookmarklets</a></h3>
403
404         <p>Below are some <span class="QUOTE">"bookmarklets"</span> to allow
405         you to easily access a <span class="QUOTE">"mini"</span> version of
406         some of <span class="APPLICATION">Privoxy's</span> special pages.
407         They are designed for MS Internet Explorer, but should work equally
408         well in Netscape, Mozilla, and other browsers which support
409         JavaScript. They are designed to run directly from your bookmarks -
410         not by clicking the links below (although that should work for
411         testing).</p>
412
413         <p>To save them, right-click the link and choose <span class=
414         "QUOTE">"Add to Favorites"</span> (IE) or <span class="QUOTE">"Add
415         Bookmark"</span> (Netscape). You will get a warning that the bookmark
416         <span class="QUOTE">"may not be safe"</span> - just click OK. Then
417         you can run the Bookmarklet directly from your favorites/bookmarks.
418         For even faster access, you can put them on the <span class=
419         "QUOTE">"Links"</span> bar (IE) or the <span class="QUOTE">"Personal
420         Toolbar"</span> (Netscape), and run them with a single click.</p>
421
422         <ul>
423           <li>
424             <p><a href=
425             "javascript:void(window.open('http://config.privoxy.org/toggle?mini=y&amp;set=enabled','ijbstatus','width=250,height=100,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no').focus());"
426             target="_top">Privoxy - Enable</a></p>
427           </li>
428
429           <li>
430             <p><a href=
431             "javascript:void(window.open('http://config.privoxy.org/toggle?mini=y&amp;set=disabled','ijbstatus','width=250,height=100,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no').focus());"
432             target="_top">Privoxy - Disable</a></p>
433           </li>
434
435           <li>
436             <p><a href=
437             "javascript:void(window.open('http://config.privoxy.org/toggle?mini=y&amp;set=toggle','ijbstatus','width=250,height=100,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no').focus());"
438             target="_top">Privoxy - Toggle Privoxy</a> (Toggles between
439             enabled and disabled)</p>
440           </li>
441
442           <li>
443             <p><a href=
444             "javascript:void(window.open('http://config.privoxy.org/toggle?mini=y','ijbstatus','width=250,height=2,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no').focus());"
445             target="_top">Privoxy- View Status</a></p>
446           </li>
447
448           <li>
449             <p><a href=
450             "javascript:void(window.open('http://config.privoxy.org/show-url-info?url='+escape(location.href),'Why').focus());"
451             target="_top">Privoxy - Why?</a></p>
452           </li>
453         </ul>
454
455         <p>Credit: The site which gave us the general idea for these
456         bookmarklets is <a href="http://www.bookmarklets.com/" target=
457         "_top">www.bookmarklets.com</a>. They have more information about
458         bookmarklets.</p>
459       </div>
460     </div>
461
462     <div class="SECT2">
463       <h2 class="SECT2"><a name="CHAIN" id="CHAIN">14.3. Chain of
464       Events</a></h2>
465
466       <p>Let's take a quick look at how some of <span class=
467       "APPLICATION">Privoxy's</span> core features are triggered, and the
468       ensuing sequence of events when a web page is requested by your
469       browser:</p>
470
471       <ul>
472         <li>
473           <p>First, your web browser requests a web page. The browser knows
474           to send the request to <span class="APPLICATION">Privoxy</span>,
475           which will in turn, relay the request to the remote web server
476           after passing the following tests:</p>
477         </li>
478
479         <li>
480           <p><span class="APPLICATION">Privoxy</span> traps any request for
481           its own internal CGI pages (e.g <a href="http://p.p/" target=
482           "_top">http://p.p/</a>) and sends the CGI page back to the
483           browser.</p>
484         </li>
485
486         <li>
487           <p>Next, <span class="APPLICATION">Privoxy</span> checks to see if
488           the URL matches any <a href="actions-file.html#BLOCK"><span class=
489           "QUOTE">"+block"</span></a> patterns. If so, the URL is then
490           blocked, and the remote web server will not be contacted. <a href=
491           "actions-file.html#HANDLE-AS-IMAGE"><span class=
492           "QUOTE">"+handle-as-image"</span></a> and <a href=
493           "actions-file.html#HANDLE-AS-EMPTY-DOCUMENT"><span class=
494           "QUOTE">"+handle-as-empty-document"</span></a> are then checked,
495           and if there is no match, an HTML <span class=
496           "QUOTE">"BLOCKED"</span> page is sent back to the browser.
497           Otherwise, if it does match, an image is returned for the former,
498           and an empty text document for the latter. The type of image would
499           depend on the setting of <a href=
500           "actions-file.html#SET-IMAGE-BLOCKER"><span class=
501           "QUOTE">"+set-image-blocker"</span></a> (blank, checkerboard
502           pattern, or an HTTP redirect to an image elsewhere).</p>
503         </li>
504
505         <li>
506           <p>Untrusted URLs are blocked. If URLs are being added to the
507           <tt class="FILENAME">trust</tt> file, then that is done.</p>
508         </li>
509
510         <li>
511           <p>If the URL pattern matches the <a href=
512           "actions-file.html#FAST-REDIRECTS"><span class=
513           "QUOTE">"+fast-redirects"</span></a> action, it is then processed.
514           Unwanted parts of the requested URL are stripped.</p>
515         </li>
516
517         <li>
518           <p>Now the rest of the client browser's request headers are
519           processed. If any of these match any of the relevant actions (e.g.
520           <a href="actions-file.html#HIDE-USER-AGENT"><span class=
521           "QUOTE">"+hide-user-agent"</span></a>, etc.), headers are
522           suppressed or forged as determined by these actions and their
523           parameters.</p>
524         </li>
525
526         <li>
527           <p>Now the web server starts sending its response back (i.e.
528           typically a web page).</p>
529         </li>
530
531         <li>
532           <p>First, the server headers are read and processed to determine,
533           among other things, the MIME type (document type) and encoding. The
534           headers are then filtered as determined by the <a href=
535           "actions-file.html#CRUNCH-INCOMING-COOKIES"><span class=
536           "QUOTE">"+crunch-incoming-cookies"</span></a>, <a href=
537           "actions-file.html#SESSION-COOKIES-ONLY"><span class=
538           "QUOTE">"+session-cookies-only"</span></a>, and <a href=
539           "actions-file.html#DOWNGRADE-HTTP-VERSION"><span class=
540           "QUOTE">"+downgrade-http-version"</span></a> actions.</p>
541         </li>
542
543         <li>
544           <p>If any <a href="actions-file.html#FILTER"><span class=
545           "QUOTE">"+filter"</span></a> action or <a href=
546           "actions-file.html#DEANIMATE-GIFS"><span class=
547           "QUOTE">"+deanimate-gifs"</span></a> action applies (and the
548           document type fits the action), the rest of the page is read into
549           memory (up to a configurable limit). Then the filter rules (from
550           <tt class="FILENAME">default.filter</tt> and any other filter
551           files) are processed against the buffered content. Filters are
552           applied in the order they are specified in one of the filter files.
553           Animated GIFs, if present, are reduced to either the first or last
554           frame, depending on the action setting.The entire page, which is
555           now filtered, is then sent by <span class=
556           "APPLICATION">Privoxy</span> back to your browser.</p>
557
558           <p>If neither a <a href="actions-file.html#FILTER"><span class=
559           "QUOTE">"+filter"</span></a> action or <a href=
560           "actions-file.html#DEANIMATE-GIFS"><span class=
561           "QUOTE">"+deanimate-gifs"</span></a> matches, then <span class=
562           "APPLICATION">Privoxy</span> passes the raw data through to the
563           client browser as it becomes available.</p>
564         </li>
565
566         <li>
567           <p>As the browser receives the now (possibly filtered) page
568           content, it reads and then requests any URLs that may be embedded
569           within the page source, e.g. ad images, stylesheets, JavaScript,
570           other HTML documents (e.g. frames), sounds, etc. For each of these
571           objects, the browser issues a separate request (this is easily
572           viewable in <span class="APPLICATION">Privoxy's</span> logs). And
573           each such request is in turn processed just as above. Note that a
574           complex web page will have many, many such embedded URLs. If these
575           secondary requests are to a different server, then quite possibly a
576           very differing set of actions is triggered.</p>
577         </li>
578       </ul>
579
580       <p>NOTE: This is somewhat of a simplistic overview of what happens with
581       each URL request. For the sake of brevity and simplicity, we have
582       focused on <span class="APPLICATION">Privoxy's</span> core features
583       only.</p>
584     </div>
585
586     <div class="SECT2">
587       <h2 class="SECT2"><a name="ACTIONSANAT" id="ACTIONSANAT">14.4.
588       Troubleshooting: Anatomy of an Action</a></h2>
589
590       <p>The way <span class="APPLICATION">Privoxy</span> applies <a href=
591       "actions-file.html#ACTIONS">actions</a> and <a href=
592       "actions-file.html#FILTER">filters</a> to any given URL can be complex,
593       and not always so easy to understand what is happening. And sometimes
594       we need to be able to <span class="emphasis"><i class=
595       "EMPHASIS">see</i></span> just what <span class=
596       "APPLICATION">Privoxy</span> is doing. Especially, if something
597       <span class="APPLICATION">Privoxy</span> is doing is causing us a
598       problem inadvertently. It can be a little daunting to look at the
599       actions and filters files themselves, since they tend to be filled with
600       <a href="appendix.html#REGEX">regular expressions</a> whose
601       consequences are not always so obvious.</p>
602
603       <p>One quick test to see if <span class="APPLICATION">Privoxy</span> is
604       causing a problem or not, is to disable it temporarily. This should be
605       the first troubleshooting step. See <a href=
606       "appendix.html#BOOKMARKLETS">the Bookmarklets</a> section on a quick
607       and easy way to do this (be sure to flush caches afterward!). Looking
608       at the logs is a good idea too. (Note that both the toggle feature and
609       logging are enabled via <tt class="FILENAME">config</tt> file settings,
610       and may need to be turned <span class="QUOTE">"on"</span>.)</p>
611
612       <p>Another easy troubleshooting step to try is if you have done any
613       customization of your installation, revert back to the installed
614       defaults and see if that helps. There are times the developers get
615       complaints about one thing or another, and the problem is more related
616       to a customized configuration issue.</p>
617
618       <p><span class="APPLICATION">Privoxy</span> also provides the <a href=
619       "http://config.privoxy.org/show-url-info" target=
620       "_top">http://config.privoxy.org/show-url-info</a> page that can show
621       us very specifically how <span class="APPLICATION">actions</span> are
622       being applied to any given URL. This is a big help for
623       troubleshooting.</p>
624
625       <p>First, enter one URL (or partial URL) at the prompt, and then
626       <span class="APPLICATION">Privoxy</span> will tell us how the current
627       configuration will handle it. This will not help with filtering effects
628       (i.e. the <a href="actions-file.html#FILTER"><span class=
629       "QUOTE">"+filter"</span></a> action) from one of the filter files since
630       this is handled very differently and not so easy to trap! It also will
631       not tell you about any other URLs that may be embedded within the URL
632       you are testing. For instance, images such as ads are expressed as URLs
633       within the raw page source of HTML pages. So you will only get info for
634       the actual URL that is pasted into the prompt area -- not any sub-URLs.
635       If you want to know about embedded URLs like ads, you will have to dig
636       those out of the HTML source. Use your browser's <span class=
637       "QUOTE">"View Page Source"</span> option for this. Or right click on
638       the ad, and grab the URL.</p>
639
640       <p>Let's try an example, <a href="http://google.com" target=
641       "_top">google.com</a>, and look at it one section at a time in a sample
642       configuration (your real configuration may vary):</p>
643
644       <table border="0" bgcolor="#E0E0E0" width="100%">
645         <tr>
646           <td>
647             <pre class="SCREEN">
648  Matches for http://www.google.com:
649
650  In file: default.action <span class="GUIBUTTON">[ View ]</span> <span class=
651 "GUIBUTTON">[ Edit ]</span>
652
653  {+change-x-forwarded-for{block}
654  +deanimate-gifs {last}
655  +fast-redirects {check-decoded-url}
656  +filter {refresh-tags}
657  +filter {img-reorder}
658  +filter {banners-by-size}
659  +filter {webbugs}
660  +filter {jumping-windows}
661  +filter {ie-exploits}
662  +hide-from-header {block}
663  +hide-referrer {forge}
664  +session-cookies-only
665  +set-image-blocker {pattern}
666 /
667
668  { -session-cookies-only }
669  .google.com
670
671  { -fast-redirects }
672  .google.com
673
674 In file: user.action <span class="GUIBUTTON">[ View ]</span> <span class=
675 "GUIBUTTON">[ Edit ]</span>
676 (no matches in this file)
677 </pre>
678           </td>
679         </tr>
680       </table>
681
682       <p>This is telling us how we have defined our <a href=
683       "actions-file.html#ACTIONS"><span class="QUOTE">"actions"</span></a>,
684       and which ones match for our test case, <span class=
685       "QUOTE">"google.com"</span>. Displayed is all the actions that are
686       available to us. Remember, the <tt class="LITERAL">+</tt> sign denotes
687       <span class="QUOTE">"on"</span>. <tt class="LITERAL">-</tt> denotes
688       <span class="QUOTE">"off"</span>. So some are <span class=
689       "QUOTE">"on"</span> here, but many are <span class=
690       "QUOTE">"off"</span>. Each example we try may provide a slightly
691       different end result, depending on our configuration directives.</p>
692
693       <p>The first listing is for our <tt class=
694       "FILENAME">default.action</tt> file. The large, multi-line listing, is
695       how the actions are set to match for all URLs, i.e. our default
696       settings. If you look at your <span class="QUOTE">"actions"</span>
697       file, this would be the section just below the <span class=
698       "QUOTE">"aliases"</span> section near the top. This will apply to all
699       URLs as signified by the single forward slash at the end of the listing
700       -- <span class="QUOTE">" / "</span>.</p>
701
702       <p>But we have defined additional actions that would be exceptions to
703       these general rules, and then we list specific URLs (or patterns) that
704       these exceptions would apply to. Last match wins. Just below this then
705       are two explicit matches for <span class="QUOTE">".google.com"</span>.
706       The first is negating our previous cookie setting, which was for
707       <a href="actions-file.html#SESSION-COOKIES-ONLY"><span class=
708       "QUOTE">"+session-cookies-only"</span></a> (i.e. not persistent). So we
709       will allow persistent cookies for google, at least that is how it is in
710       this example. The second turns <span class="emphasis"><i class=
711       "EMPHASIS">off</i></span> any <a href=
712       "actions-file.html#FAST-REDIRECTS"><span class=
713       "QUOTE">"+fast-redirects"</span></a> action, allowing this to take
714       place unmolested. Note that there is a leading dot here -- <span class=
715       "QUOTE">".google.com"</span>. This will match any hosts and
716       sub-domains, in the google.com domain also, such as <span class=
717       "QUOTE">"www.google.com"</span> or <span class=
718       "QUOTE">"mail.google.com"</span>. But it would not match <span class=
719       "QUOTE">"www.google.de"</span>! So, apparently, we have these two
720       actions defined as exceptions to the general rules at the top somewhere
721       in the lower part of our <tt class="FILENAME">default.action</tt> file,
722       and <span class="QUOTE">"google.com"</span> is referenced somewhere in
723       these latter sections.</p>
724
725       <p>Then, for our <tt class="FILENAME">user.action</tt> file, we again
726       have no hits. So there is nothing google-specific that we might have
727       added to our own, local configuration. If there was, those actions
728       would over-rule any actions from previously processed files, such as
729       <tt class="FILENAME">default.action</tt>. <tt class=
730       "FILENAME">user.action</tt> typically has the last word. This is the
731       best place to put hard and fast exceptions,</p>
732
733       <p>And finally we pull it all together in the bottom section and
734       summarize how <span class="APPLICATION">Privoxy</span> is applying all
735       its <span class="QUOTE">"actions"</span> to <span class=
736       "QUOTE">"google.com"</span>:</p>
737
738       <table border="0" bgcolor="#E0E0E0" width="100%">
739         <tr>
740           <td>
741             <pre class="SCREEN">
742 &#13; Final results:
743
744  -add-header
745  -block
746  +change-x-forwarded-for{block}
747  -client-header-filter{hide-tor-exit-notation}
748  -content-type-overwrite
749  -crunch-client-header
750  -crunch-if-none-match
751  -crunch-incoming-cookies
752  -crunch-outgoing-cookies
753  -crunch-server-header
754  +deanimate-gifs {last}
755  -downgrade-http-version
756  -fast-redirects
757  -filter {js-events}
758  -filter {content-cookies}
759  -filter {all-popups}
760  -filter {banners-by-link}
761  -filter {tiny-textforms}
762  -filter {frameset-borders}
763  -filter {demoronizer}
764  -filter {shockwave-flash}
765  -filter {quicktime-kioskmode}
766  -filter {fun}
767  -filter {crude-parental}
768  -filter {site-specifics}
769  -filter {js-annoyances}
770  -filter {html-annoyances}
771  +filter {refresh-tags}
772  -filter {unsolicited-popups}
773  +filter {img-reorder}
774  +filter {banners-by-size}
775  +filter {webbugs}
776  +filter {jumping-windows}
777  +filter {ie-exploits}
778  -filter {google}
779  -filter {yahoo}
780  -filter {msn}
781  -filter {blogspot}
782  -filter {no-ping}
783  -force-text-mode
784  -handle-as-empty-document
785  -handle-as-image
786  -hide-accept-language
787  -hide-content-disposition
788  +hide-from-header {block}
789  -hide-if-modified-since
790  +hide-referrer {forge}
791  -hide-user-agent
792  -limit-connect
793  -overwrite-last-modified
794  -prevent-compression
795  -redirect
796  -server-header-filter{xml-to-html}
797  -server-header-filter{html-to-xml}
798  -session-cookies-only
799  +set-image-blocker {pattern}
800 </pre>
801           </td>
802         </tr>
803       </table>
804
805       <p>Notice the only difference here to the previous listing, is to
806       <span class="QUOTE">"fast-redirects"</span> and <span class=
807       "QUOTE">"session-cookies-only"</span>, which are activated specifically
808       for this site in our configuration, and thus show in the <span class=
809       "QUOTE">"Final Results"</span>.</p>
810
811       <p>Now another example, <span class=
812       "QUOTE">"ad.doubleclick.net"</span>:</p>
813
814       <table border="0" bgcolor="#E0E0E0" width="100%">
815         <tr>
816           <td>
817             <pre class="SCREEN">
818 &#13; { +block{Domains starts with "ad"} }
819   ad*.
820
821  { +block{Domain contains "ad"} }
822   .ad.
823
824  { +block{Doubleclick banner server} +handle-as-image }
825   .[a-vx-z]*.doubleclick.net
826 </pre>
827           </td>
828         </tr>
829       </table>
830
831       <p>We'll just show the interesting part here - the explicit matches. It
832       is matched three different times. Two <span class=
833       "QUOTE">"+block{}"</span> sections, and a <span class="QUOTE">"+block{}
834       +handle-as-image"</span>, which is the expanded form of one of our
835       aliases that had been defined as: <span class=
836       "QUOTE">"+block-as-image"</span>. (<a href=
837       "actions-file.html#ALIASES"><span class="QUOTE">"Aliases"</span></a>
838       are defined in the first section of the actions file and typically used
839       to combine more than one action.)</p>
840
841       <p>Any one of these would have done the trick and blocked this as an
842       unwanted image. This is unnecessarily redundant since the last case
843       effectively would also cover the first. No point in taking chances with
844       these guys though ;-) Note that if you want an ad or obnoxious URL to
845       be invisible, it should be defined as <span class=
846       "QUOTE">"ad.doubleclick.net"</span> is done here -- as both a <a href=
847       "actions-file.html#BLOCK"><span class="QUOTE">"+block{}"</span></a>
848       <span class="emphasis"><i class="EMPHASIS">and</i></span> an <a href=
849       "actions-file.html#HANDLE-AS-IMAGE"><span class=
850       "QUOTE">"+handle-as-image"</span></a>. The custom alias <span class=
851       "QUOTE">"<tt class="LITERAL">+block-as-image</tt>"</span> just
852       simplifies the process and make it more readable.</p>
853
854       <p>One last example. Let's try <span class=
855       "QUOTE">"http://www.example.net/adsl/HOWTO/"</span>. This one is giving
856       us problems. We are getting a blank page. Hmmm ...</p>
857
858       <table border="0" bgcolor="#E0E0E0" width="100%">
859         <tr>
860           <td>
861             <pre class="SCREEN">
862 &#13; Matches for http://www.example.net/adsl/HOWTO/:
863
864  In file: default.action <span class="GUIBUTTON">[ View ]</span> <span class=
865 "GUIBUTTON">[ Edit ]</span>
866
867  {-add-header
868   -block
869   +change-x-forwarded-for{block}
870   -client-header-filter{hide-tor-exit-notation}
871   -content-type-overwrite
872   -crunch-client-header
873   -crunch-if-none-match
874   -crunch-incoming-cookies
875   -crunch-outgoing-cookies
876   -crunch-server-header
877   +deanimate-gifs
878   -downgrade-http-version
879   +fast-redirects {check-decoded-url}
880   -filter {js-events}
881   -filter {content-cookies}
882   -filter {all-popups}
883   -filter {banners-by-link}
884   -filter {tiny-textforms}
885   -filter {frameset-borders}
886   -filter {demoronizer}
887   -filter {shockwave-flash}
888   -filter {quicktime-kioskmode}
889   -filter {fun}
890   -filter {crude-parental}
891   -filter {site-specifics}
892   -filter {js-annoyances}
893   -filter {html-annoyances}
894   +filter {refresh-tags}
895   -filter {unsolicited-popups}
896   +filter {img-reorder}
897   +filter {banners-by-size}
898   +filter {webbugs}
899   +filter {jumping-windows}
900   +filter {ie-exploits}
901   -filter {google}
902   -filter {yahoo}
903   -filter {msn}
904   -filter {blogspot}
905   -filter {no-ping}
906   -force-text-mode
907   -handle-as-empty-document
908   -handle-as-image
909   -hide-accept-language
910   -hide-content-disposition
911   +hide-from-header{block}
912   +hide-referer{forge}
913   -hide-user-agent
914   -overwrite-last-modified
915   +prevent-compression
916   -redirect
917   -server-header-filter{xml-to-html}
918   -server-header-filter{html-to-xml}
919   +session-cookies-only
920   +set-image-blocker{blank} }
921    /
922
923  { +block{Path contains "ads".} +handle-as-image }
924   /ads
925 </pre>
926           </td>
927         </tr>
928       </table>
929
930       <p>Ooops, the <span class="QUOTE">"/adsl/"</span> is matching
931       <span class="QUOTE">"/ads"</span> in our configuration! But we did not
932       want this at all! Now we see why we get the blank page. It is actually
933       triggering two different actions here, and the effects are aggregated
934       so that the URL is blocked, and <span class=
935       "APPLICATION">Privoxy</span> is told to treat the block as if it were
936       an image. But this is, of course, all wrong. We could now add a new
937       action below this (or better in our own <tt class=
938       "FILENAME">user.action</tt> file) that explicitly <span class=
939       "emphasis"><i class="EMPHASIS">un</i></span> blocks ( <a href=
940       "actions-file.html#BLOCK"><span class="QUOTE">"{-block}"</span></a>)
941       paths with <span class="QUOTE">"adsl"</span> in them (remember, last
942       match in the configuration wins). There are various ways to handle such
943       exceptions. Example:</p>
944
945       <table border="0" bgcolor="#E0E0E0" width="100%">
946         <tr>
947           <td>
948             <pre class="SCREEN">
949 &#13; { -block }
950   /adsl
951 </pre>
952           </td>
953         </tr>
954       </table>
955
956       <p>Now the page displays ;-) Remember to flush your browser's caches
957       when making these kinds of changes to your configuration to insure that
958       you get a freshly delivered page! Or, try using <tt class=
959       "LITERAL">Shift+Reload</tt>.</p>
960
961       <p>But now what about a situation where we get no explicit matches like
962       we did with:</p>
963
964       <table border="0" bgcolor="#E0E0E0" width="100%">
965         <tr>
966           <td>
967             <pre class="SCREEN">
968 &#13; { +block{Path starts with "ads".} +handle-as-image }
969  /ads
970 </pre>
971           </td>
972         </tr>
973       </table>
974
975       <p>That actually was very helpful and pointed us quickly to where the
976       problem was. If you don't get this kind of match, then it means one of
977       the default rules in the first section of <tt class=
978       "FILENAME">default.action</tt> is causing the problem. This would
979       require some guesswork, and maybe a little trial and error to isolate
980       the offending rule. One likely cause would be one of the <a href=
981       "actions-file.html#FILTER"><span class="QUOTE">"+filter"</span></a>
982       actions. These tend to be harder to troubleshoot. Try adding the URL
983       for the site to one of aliases that turn off <a href=
984       "actions-file.html#FILTER"><span class=
985       "QUOTE">"+filter"</span></a>:</p>
986
987       <table border="0" bgcolor="#E0E0E0" width="100%">
988         <tr>
989           <td>
990             <pre class="SCREEN">
991 &#13; { shop }
992  .quietpc.com
993  .worldpay.com   # for quietpc.com
994  .jungle.com
995  .scan.co.uk
996  .forbes.com
997 </pre>
998           </td>
999         </tr>
1000       </table>
1001
1002       <p><span class="QUOTE">"<tt class="LITERAL">{ shop }</tt>"</span> is an
1003       <span class="QUOTE">"alias"</span> that expands to <span class=
1004       "QUOTE">"<tt class="LITERAL">{ -filter -session-cookies-only
1005       }</tt>"</span>. Or you could do your own exception to negate
1006       filtering:</p>
1007
1008       <table border="0" bgcolor="#E0E0E0" width="100%">
1009         <tr>
1010           <td>
1011             <pre class="SCREEN">
1012 &#13; { -filter }
1013  # Disable ALL filter actions for sites in this section
1014  .forbes.com
1015  developer.ibm.com
1016  localhost
1017 </pre>
1018           </td>
1019         </tr>
1020       </table>
1021
1022       <p>This would turn off all filtering for these sites. This is best put
1023       in <tt class="FILENAME">user.action</tt>, for local site exceptions.
1024       Note that when a simple domain pattern is used by itself (without the
1025       subsequent path portion), all sub-pages within that domain are included
1026       automatically in the scope of the action.</p>
1027
1028       <p>Images that are inexplicably being blocked, may well be hitting the
1029       <a href="actions-file.html#FILTER-BANNERS-BY-SIZE"><span class=
1030       "QUOTE">"+filter{banners-by-size}"</span></a> rule, which assumes that
1031       images of certain sizes are ad banners (works well <span class=
1032       "emphasis"><i class="EMPHASIS">most of the time</i></span> since these
1033       tend to be standardized).</p>
1034
1035       <p><span class="QUOTE">"<tt class="LITERAL">{ fragile }</tt>"</span> is
1036       an alias that disables most actions that are the most likely to cause
1037       trouble. This can be used as a last resort for problem sites.</p>
1038
1039       <table border="0" bgcolor="#E0E0E0" width="100%">
1040         <tr>
1041           <td>
1042             <pre class="SCREEN">
1043 &#13; { fragile }
1044  # Handle with care: easy to break
1045  mail.google.
1046  mybank.example.com
1047 </pre>
1048           </td>
1049         </tr>
1050       </table>
1051
1052       <p><span class="emphasis"><i class="EMPHASIS">Remember to flush
1053       caches!</i></span> Note that the <tt class="LITERAL">mail.google</tt>
1054       reference lacks the TLD portion (e.g. <span class=
1055       "QUOTE">".com"</span>). This will effectively match any TLD with
1056       <tt class="LITERAL">google</tt> in it, such as <tt class=
1057       "LITERAL">mail.google.de.</tt>, just as an example.</p>
1058
1059       <p>If this still does not work, you will have to go through the
1060       remaining actions one by one to find which one(s) is causing the
1061       problem.</p>
1062     </div>
1063   </div>
1064
1065   <div class="NAVFOOTER">
1066     <hr align="left" width="100%">
1067
1068     <table summary="Footer navigation table" width="100%" border="0"
1069     cellpadding="0" cellspacing="0">
1070       <tr>
1071         <td width="33%" align="left" valign="top"><a href="seealso.html"
1072         accesskey="P">Prev</a></td>
1073
1074         <td width="34%" align="center" valign="top"><a href="index.html"
1075         accesskey="H">Home</a></td>
1076
1077         <td width="33%" align="right" valign="top">&nbsp;</td>
1078       </tr>
1079
1080       <tr>
1081         <td width="33%" align="left" valign="top">See Also</td>
1082
1083         <td width="34%" align="center" valign="top">&nbsp;</td>
1084
1085         <td width="33%" align="right" valign="top">&nbsp;</td>
1086       </tr>
1087     </table>
1088   </div>
1089 </body>
1090 </html>