4e14ccc74d
Instiki now runs on the Rails 2.3.0 Candidate Release. Among other improvements, this means that it now automagically selects between WEBrick and Mongrel. Just run ./instiki --daemon
289 lines
15 KiB
HTML
289 lines
15 KiB
HTML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title>Class: Rack::Deflater</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
<script type="text/javascript">
|
|
// <![CDATA[
|
|
|
|
function popupCode( url ) {
|
|
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
}
|
|
|
|
function toggleCode( id ) {
|
|
if ( document.getElementById )
|
|
elem = document.getElementById( id );
|
|
else if ( document.all )
|
|
elem = eval( "document.all." + id );
|
|
else
|
|
return false;
|
|
|
|
elemStyle = elem.style;
|
|
|
|
if ( elemStyle.display != "block" ) {
|
|
elemStyle.display = "block"
|
|
} else {
|
|
elemStyle.display = "none"
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// Make codeblocks hidden by default
|
|
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
|
|
// ]]>
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
|
|
|
|
<div id="classHeader">
|
|
<table class="header-table">
|
|
<tr class="top-aligned-row">
|
|
<td><strong>Class</strong></td>
|
|
<td class="class-name-in-header">Rack::Deflater</td>
|
|
</tr>
|
|
<tr class="top-aligned-row">
|
|
<td><strong>In:</strong></td>
|
|
<td>
|
|
<a href="../../files/lib/rack/deflater_rb.html">
|
|
lib/rack/deflater.rb
|
|
</a>
|
|
<br />
|
|
</td>
|
|
</tr>
|
|
|
|
<tr class="top-aligned-row">
|
|
<td><strong>Parent:</strong></td>
|
|
<td>
|
|
Object
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<!-- banner header -->
|
|
|
|
<div id="bodyContent">
|
|
|
|
|
|
|
|
<div id="contextContent">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<div id="method-list">
|
|
<h3 class="section-bar">Methods</h3>
|
|
|
|
<div class="name-list">
|
|
<a href="#M000151">call</a>
|
|
<a href="#M000153">deflate</a>
|
|
<a href="#M000152">gzip</a>
|
|
<a href="#M000150">new</a>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<!-- if includes -->
|
|
|
|
<div id="section">
|
|
|
|
|
|
<div id="constants-list">
|
|
<h3 class="section-bar">Constants</h3>
|
|
|
|
<div class="name-list">
|
|
<table summary="Constants">
|
|
<tr class="top-aligned-row context-row">
|
|
<td class="context-item-name">DEFLATE_ARGS</td>
|
|
<td>=</td>
|
|
<td class="context-item-value">[ Zlib::DEFAULT_COMPRESSION, # drop the zlib header which causes both Safari and IE to choke -Zlib::MAX_WBITS, Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- if method_list -->
|
|
<div id="methods">
|
|
<h3 class="section-bar">Public Class methods</h3>
|
|
|
|
<div id="method-M000153" class="method-detail">
|
|
<a name="M000153"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000153" class="method-signature">
|
|
<span class="method-name">deflate</span><span class="method-args">(body)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p>
|
|
Loosely based on Mongrel‘s Deflate handler
|
|
</p>
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000153-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000153-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File lib/rack/deflater.rb, line 77</span>
|
|
77: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">deflate</span>(<span class="ruby-identifier">body</span>)
|
|
78: <span class="ruby-identifier">deflater</span> = <span class="ruby-constant">Zlib</span><span class="ruby-operator">::</span><span class="ruby-constant">Deflate</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-constant">DEFLATE_ARGS</span>)
|
|
79:
|
|
80: <span class="ruby-comment cmt"># TODO: Add streaming</span>
|
|
81: <span class="ruby-identifier">body</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">part</span><span class="ruby-operator">|</span> <span class="ruby-identifier">deflater</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">part</span> }
|
|
82:
|
|
83: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">deflater</span>.<span class="ruby-identifier">finish</span>
|
|
84: <span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="method-M000152" class="method-detail">
|
|
<a name="M000152"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000152" class="method-signature">
|
|
<span class="method-name">gzip</span><span class="method-args">(body, mtime)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000152-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000152-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File lib/rack/deflater.rb, line 56</span>
|
|
56: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">gzip</span>(<span class="ruby-identifier">body</span>, <span class="ruby-identifier">mtime</span>)
|
|
57: <span class="ruby-identifier">io</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
|
|
58: <span class="ruby-identifier">gzip</span> = <span class="ruby-constant">Zlib</span><span class="ruby-operator">::</span><span class="ruby-constant">GzipWriter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">io</span>)
|
|
59: <span class="ruby-identifier">gzip</span>.<span class="ruby-identifier">mtime</span> = <span class="ruby-identifier">mtime</span>
|
|
60:
|
|
61: <span class="ruby-comment cmt"># TODO: Add streaming</span>
|
|
62: <span class="ruby-identifier">body</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">part</span><span class="ruby-operator">|</span> <span class="ruby-identifier">gzip</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">part</span> }
|
|
63:
|
|
64: <span class="ruby-identifier">gzip</span>.<span class="ruby-identifier">close</span>
|
|
65: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">io</span>.<span class="ruby-identifier">string</span>
|
|
66: <span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="method-M000150" class="method-detail">
|
|
<a name="M000150"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000150" class="method-signature">
|
|
<span class="method-name">new</span><span class="method-args">(app)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000150-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000150-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File lib/rack/deflater.rb, line 8</span>
|
|
8: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">app</span>)
|
|
9: <span class="ruby-ivar">@app</span> = <span class="ruby-identifier">app</span>
|
|
10: <span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 class="section-bar">Public Instance methods</h3>
|
|
|
|
<div id="method-M000151" class="method-detail">
|
|
<a name="M000151"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000151" class="method-signature">
|
|
<span class="method-name">call</span><span class="method-args">(env)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000151-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000151-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File lib/rack/deflater.rb, line 12</span>
|
|
12: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
|
|
13: <span class="ruby-identifier">status</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">body</span> = <span class="ruby-ivar">@app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
|
|
14: <span class="ruby-identifier">headers</span> = <span class="ruby-constant">Utils</span><span class="ruby-operator">::</span><span class="ruby-constant">HeaderHash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">headers</span>)
|
|
15:
|
|
16: <span class="ruby-comment cmt"># Skip compressing empty entity body responses and responses with</span>
|
|
17: <span class="ruby-comment cmt"># no-transform set.</span>
|
|
18: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Utils</span><span class="ruby-operator">::</span><span class="ruby-constant">STATUS_WITH_NO_ENTITY_BODY</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">status</span>) <span class="ruby-operator">||</span>
|
|
19: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">'Cache-Control'</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\bno-transform\b/</span>
|
|
20: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">status</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">body</span>]
|
|
21: <span class="ruby-keyword kw">end</span>
|
|
22:
|
|
23: <span class="ruby-identifier">request</span> = <span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">env</span>)
|
|
24:
|
|
25: <span class="ruby-identifier">encoding</span> = <span class="ruby-constant">Utils</span>.<span class="ruby-identifier">select_best_encoding</span>(<span class="ruby-node">%w(gzip deflate identity)</span>,
|
|
26: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">accept_encoding</span>)
|
|
27:
|
|
28: <span class="ruby-comment cmt"># Set the Vary HTTP header.</span>
|
|
29: <span class="ruby-identifier">vary</span> = <span class="ruby-identifier">headers</span>[<span class="ruby-value str">"Vary"</span>].<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">","</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">strip</span> }
|
|
30: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">vary</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">"*"</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">vary</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">"Accept-Encoding"</span>)
|
|
31: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">"Vary"</span>] = <span class="ruby-identifier">vary</span>.<span class="ruby-identifier">push</span>(<span class="ruby-value str">"Accept-Encoding"</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">","</span>)
|
|
32: <span class="ruby-keyword kw">end</span>
|
|
33:
|
|
34: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">encoding</span>
|
|
35: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"gzip"</span>
|
|
36: <span class="ruby-identifier">mtime</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value str">"Last-Modified"</span>)
|
|
37: <span class="ruby-constant">Time</span>.<span class="ruby-identifier">httpdate</span>(<span class="ruby-identifier">headers</span>[<span class="ruby-value str">"Last-Modified"</span>])
|
|
38: <span class="ruby-keyword kw">else</span>
|
|
39: <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
|
|
40: <span class="ruby-keyword kw">end</span>
|
|
41: [<span class="ruby-identifier">status</span>,
|
|
42: <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-value str">"Content-Encoding"</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"gzip"</span>),
|
|
43: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">gzip</span>(<span class="ruby-identifier">body</span>, <span class="ruby-identifier">mtime</span>)]
|
|
44: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"deflate"</span>
|
|
45: [<span class="ruby-identifier">status</span>,
|
|
46: <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-value str">"Content-Encoding"</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"deflate"</span>),
|
|
47: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">deflate</span>(<span class="ruby-identifier">body</span>)]
|
|
48: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"identity"</span>
|
|
49: [<span class="ruby-identifier">status</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">body</span>]
|
|
50: <span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span>
|
|
51: <span class="ruby-identifier">message</span> = [<span class="ruby-node">"An acceptable encoding for the requested resource #{request.fullpath} could not be found."</span>]
|
|
52: [<span class="ruby-value">406</span>, {<span class="ruby-value str">"Content-Type"</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"text/plain"</span>}, <span class="ruby-identifier">message</span>]
|
|
53: <span class="ruby-keyword kw">end</span>
|
|
54: <span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div id="validator-badges">
|
|
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |