mongrel_output_compression 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
Binary file
data/COPYING ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007 Brian J. Landau
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007 Brian J. Landau
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,16 @@
1
+ == Mongrel HTTP Output Compression Handler Plugin
2
+
3
+ *Website*: http://rubyforge.org/projects/mongrel-compres
4
+
5
+ === Usage:
6
+
7
+ To use this plugin you just need to create a mongrel config script with the line:
8
+
9
+ uri '', :handler => plugin('handlers/outputcompression')
10
+
11
+ For those that have never used a mongrel config script: You could put this in a file called "mongrel.rb" in your Rails applications config directory, and then run, from your projects root directory: <tt>mongrel_rails -S config/mongrel.rb</tt>.
12
+
13
+ This is based on:
14
+ * The {Better Output Compression Plugin}[http://wiki.rubyonrails.com/rails/pages/Better+Output+Compression+Plugin] by Tom Fakes, Dan Kubb, and Sebastian.
15
+ * And the {Output Compression Plugin}[http://wiki.rubyonrails.org/rails/pages/Output+Compression+Plugin] by Jeremy Evans
16
+
data/Rakefile ADDED
@@ -0,0 +1,67 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'fileutils'
7
+ include FileUtils
8
+
9
+ version="0.1.0"
10
+ name="mongrel_output_compression"
11
+
12
+ spec = Gem::Specification.new do |s|
13
+ s.name = name
14
+ s.version = version
15
+ s.description = s.summary = "A mongrel plugin to gzip or deflate compress all output if the client supports it."
16
+ s.author = "Brian Landau"
17
+ s.homepage = "http://rubyforge.org/projects/mongrel-compres/"
18
+ s.rubyforge_project = "mongrel-compres"
19
+ s.add_dependency('gem_plugin', '>= 0.2.3')
20
+ s.add_dependency('mongrel', '>= 1.1.1')
21
+
22
+
23
+ s.platform = Gem::Platform::RUBY
24
+ s.has_rdoc = true
25
+ s.extra_rdoc_files = ["README"]
26
+
27
+ s.files = %w(COPYING LICENSE README Rakefile) +
28
+ Dir.glob("{bin,doc/rdoc,test,lib}/**/*") +
29
+ Dir.glob("resources/**/*")
30
+
31
+ s.require_path = "lib"
32
+ s.bindir = "bin"
33
+ s.test_files = Dir.glob('test/*.rb')
34
+
35
+ s.signing_key = '/Users/brianlandau/private/gem-private_key.pem'
36
+ s.cert_chain = ['/Users/brianlandau/.gem/gem-public_cert.pem']
37
+ end
38
+
39
+ Rake::GemPackageTask.new(spec) do |p|
40
+ p.need_tar = true if RUBY_PLATFORM !~ /mswin/
41
+ end
42
+
43
+ task :install => [:test, :package] do
44
+ sh %{sudo gem install pkg/#{name}-#{version}.gem}
45
+ end
46
+
47
+ task :uninstall => [:clean] do
48
+ sh %{sudo gem uninstall #{name}}
49
+ end
50
+
51
+ Rake::TestTask.new do |t|
52
+ t.libs << "test"
53
+ t.test_files = FileList['test/test*.rb']
54
+ t.verbose = true
55
+ end
56
+
57
+ Rake::RDocTask.new do |rdoc|
58
+ rdoc.rdoc_dir = 'doc/rdoc'
59
+ rdoc.options << '--line-numbers'
60
+ rdoc.rdoc_files.add ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
61
+ rdoc.options << '--main' << 'README'
62
+ end
63
+
64
+ task :default => [:test, :package]
65
+
66
+ CLEAN.include ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log', 'pkg', 'lib/*.bundle', '*.gem', '.config']
67
+
@@ -0,0 +1,152 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: OutputCompression</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">OutputCompression</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/mongrel_output_compression/init_rb.html">
59
+ lib/mongrel_output_compression/init.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ GemPlugin::Plugin&quot;/handlers&quot;
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <h2>HTTP Output Compression Handler Plugin</h2>
83
+ <p>
84
+ This class is a Mongrel web server plugin to handle a gzip/deflate response
85
+ if the client supports it.
86
+ </p>
87
+
88
+ </div>
89
+
90
+
91
+ </div>
92
+
93
+ <div id="method-list">
94
+ <h3 class="section-bar">Methods</h3>
95
+
96
+ <div class="name-list">
97
+ <a href="#M000001">process</a>&nbsp;&nbsp;
98
+ </div>
99
+ </div>
100
+
101
+ </div>
102
+
103
+
104
+ <!-- if includes -->
105
+ <div id="includes">
106
+ <h3 class="section-bar">Included Modules</h3>
107
+
108
+ <div id="includes-list">
109
+ <span class="include-name">Mongrel::HttpHandlerPlugin</span>
110
+ </div>
111
+ </div>
112
+
113
+ <div id="section">
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+ <!-- if method_list -->
123
+ <div id="methods">
124
+ <h3 class="section-bar">Public Instance methods</h3>
125
+
126
+ <div id="method-M000001" class="method-detail">
127
+ <a name="M000001"></a>
128
+
129
+ <div class="method-heading">
130
+ <a href="OutputCompression.src/M000001.html" target="Code" class="method-signature"
131
+ onclick="popupCode('OutputCompression.src/M000001.html');return false;">
132
+ <span class="method-name">process</span><span class="method-args">(request, response)</span>
133
+ </a>
134
+ </div>
135
+
136
+ <div class="method-description">
137
+ </div>
138
+ </div>
139
+
140
+
141
+ </div>
142
+
143
+
144
+ </div>
145
+
146
+
147
+ <div id="validator-badges">
148
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
149
+ </div>
150
+
151
+ </body>
152
+ </html>
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>process (OutputCompression)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel_output_compression/init.rb, line 20</span>
14
+ 20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">response</span>)
15
+ 21: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">COMPRESSION_DISABLED</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-value str">&quot;HTTP_ACCEPT_ENCODING&quot;</span>].<span class="ruby-identifier">nil?</span>
16
+ 22: <span class="ruby-keyword kw">begin</span>
17
+ 23: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-value str">&quot;HTTP_ACCEPT_ENCODING&quot;</span>].<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/\s*,\s*/</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">encoding</span><span class="ruby-operator">|</span>
18
+ 24: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">encoding</span>
19
+ 25: <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/\Agzip\b/</span>
20
+ 26: <span class="ruby-identifier">strio</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
21
+ 27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">close</span>
22
+ 28: <span class="ruby-identifier">rewind</span>
23
+ 29: <span class="ruby-keyword kw">end</span>
24
+ 30: <span class="ruby-identifier">gz</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">strio</span>)
25
+ 31: <span class="ruby-identifier">gz</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">string</span>)
26
+ 32: <span class="ruby-identifier">gz</span>.<span class="ruby-identifier">close</span>
27
+ 33: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">strio</span>
28
+ 34: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">rewind</span>
29
+ 35: <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/\Adeflate\b/</span>
30
+ 36: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Zlib</span><span class="ruby-operator">::</span><span class="ruby-constant">Deflate</span>.<span class="ruby-identifier">deflate</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">string</span>))
31
+ 37: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">rewind</span>
32
+ 38: <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/\Aidentity\b/</span>
33
+ 39: <span class="ruby-comment cmt"># do nothing for identity</span>
34
+ 40: <span class="ruby-keyword kw">else</span>
35
+ 41: <span class="ruby-keyword kw">next</span> <span class="ruby-comment cmt"># the encoding is not supported, try the next one</span>
36
+ 42: <span class="ruby-keyword kw">end</span>
37
+ 43: <span class="ruby-ivar">@content_type</span> = <span class="ruby-identifier">encoding</span>
38
+ 44: <span class="ruby-keyword kw">break</span> <span class="ruby-comment cmt"># the encoding is supported, stop</span>
39
+ 45: <span class="ruby-keyword kw">end</span>
40
+ 46: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">header</span>[<span class="ruby-value str">'Content-Encoding'</span>] = <span class="ruby-ivar">@content_type</span>
41
+ 47: <span class="ruby-comment cmt"># if response.header['Vary'] != '*'</span>
42
+ 48: <span class="ruby-comment cmt"># head['Vary'] = response.header['Vary'].to_s.split(',').push('Accept-Encoding').uniq.join(',')</span>
43
+ 49: <span class="ruby-comment cmt"># end</span>
44
+ 50: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Response body was encoded with #{@content_type}\n&quot;</span>
45
+ 51: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
46
+ 52: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Error with HTTP Compression: #{e.to_s}\n&quot;</span>
47
+ 53: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">start</span>(<span class="ruby-value">500</span>, <span class="ruby-keyword kw">true</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">head</span>, <span class="ruby-identifier">out</span><span class="ruby-operator">|</span>
48
+ 54: <span class="ruby-identifier">out</span>.<span class="ruby-identifier">write</span> <span class="ruby-node">&quot;error proceessing #{request.params['REQUEST_PATH']}\n&quot;</span>
49
+ 55: <span class="ruby-keyword kw">end</span>
50
+ 56: <span class="ruby-keyword kw">end</span>
51
+ 57: <span class="ruby-keyword kw">end</span></pre>
52
+ </body>
53
+ </html>
@@ -0,0 +1 @@
1
+ Tue, 04 Dec 2007 22:24:28 -0500
@@ -0,0 +1,129 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: COPYING</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>COPYING</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>COPYING
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Tue Dec 04 15:42:49 -0500 2007</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+ <div id="description">
72
+ <p>
73
+ Copyright (c) 2007 Brian J. Landau
74
+ </p>
75
+ <p>
76
+ Permission is hereby granted, free of charge, to any person obtaining a
77
+ copy of this software and associated documentation files (the
78
+ &quot;Software&quot;), to deal in the Software without restriction,
79
+ including without limitation the rights to use, copy, modify, merge,
80
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
81
+ permit persons to whom the Software is furnished to do so, subject to the
82
+ following conditions:
83
+ </p>
84
+ <p>
85
+ The above copyright notice and this permission notice shall be included in
86
+ all copies or substantial portions of the Software.
87
+ </p>
88
+ <p>
89
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
90
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
91
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
92
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
93
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
94
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
95
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
96
+ </p>
97
+
98
+ </div>
99
+
100
+
101
+ </div>
102
+
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+
109
+ <div id="section">
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ <!-- if method_list -->
119
+
120
+
121
+ </div>
122
+
123
+
124
+ <div id="validator-badges">
125
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
126
+ </div>
127
+
128
+ </body>
129
+ </html>