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