racknga 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,214 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Ryo Onodera <onodera@clear-code.com>
4
+ # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+
20
+ require 'stringio'
21
+
22
+ module NginxAccessLogParserTests
23
+ module Data
24
+ private
25
+ def time_log_component
26
+ times = ["03/Aug/2011:16:58:01 +0900", runtime, request_time].compact
27
+ "[#{times.join(', ')}]"
28
+ end
29
+
30
+ def usual_log_line
31
+ "127.0.0.1 - - #{time_log_component} " +
32
+ "\"GET / HTTP/1.1\" 200 613 \"-\" \"Ruby\""
33
+ end
34
+
35
+ def usual_log_entry_options
36
+ {
37
+ :remote_address => "127.0.0.1",
38
+ :remote_user => "-",
39
+ :time_local => Time.local(2011, 8, 3, 16, 58, 1),
40
+ :runtime => runtime,
41
+ :request_time => request_time,
42
+ :request => "GET / HTTP/1.1",
43
+ :status => 200,
44
+ :body_bytes_sent => 613,
45
+ :http_referer => "-",
46
+ :http_user_agent => "Ruby",
47
+ }
48
+ end
49
+
50
+ def usual_log_entry
51
+ create_log_entry(usual_log_entry_options)
52
+ end
53
+
54
+ def not_found_log_line
55
+ "127.0.0.1 - - #{time_log_component} " +
56
+ "\"GET /the-truth.html HTTP/1.1\" 404 613 \"-\" \"Ruby\""
57
+ end
58
+
59
+ def not_found_log_entry
60
+ options = {
61
+ :status => 404,
62
+ :request => "GET /the-truth.html HTTP/1.1",
63
+ }
64
+ create_log_entry(usual_log_entry_options.merge(options))
65
+ end
66
+
67
+ def utf8_path
68
+ "/トップページ.html"
69
+ end
70
+
71
+ def valid_utf8_log_line
72
+ path = utf8_path
73
+
74
+ "127.0.0.1 - - #{time_log_component} " +
75
+ "\"GET #{path} HTTP/1.1\" 200 613 \"-\" \"Ruby\""
76
+ end
77
+
78
+ def valid_utf8_log_entry
79
+ options = {
80
+ :request => "GET #{utf8_path} HTTP/1.1",
81
+ }
82
+ create_log_entry(usual_log_entry_options.merge(options))
83
+ end
84
+
85
+
86
+ def garbled_path
87
+ "/#{Random.new.bytes(10)}".force_encoding(Encoding::UTF_8)
88
+ end
89
+
90
+ def invalid_utf8_log_line
91
+ path = garbled_path
92
+
93
+ "127.0.0.1 - - #{time_log_component} " +
94
+ "\"GET #{path} HTTP/1.1\" 200 613 \"-\" \"Ruby\""
95
+ end
96
+
97
+ def bad_log_line
98
+ "bad"
99
+ end
100
+ end
101
+
102
+ module Environment
103
+ private
104
+ def create_log_entry(options)
105
+ Racknga::LogEntry.new(options)
106
+ end
107
+
108
+ def create_log_file(string)
109
+ StringIO.new(string)
110
+ end
111
+
112
+ def create_log_parser(file)
113
+ Racknga::NginxAccessLogParser.new(file)
114
+ end
115
+
116
+ def create_reversed_log_parser(file)
117
+ Racknga::ReversedNginxAccessLogParser.new(file)
118
+ end
119
+
120
+ def join_lines(*lines)
121
+ lines.collect do |line|
122
+ line + "\n"
123
+ end.join
124
+ end
125
+
126
+ def parse(string)
127
+ file = create_log_file(string)
128
+ parser = create_log_parser(file)
129
+ parser.collect.to_a
130
+ end
131
+
132
+ def reversed_parse(string)
133
+ file = create_log_file(string)
134
+ parser = create_reversed_log_parser(file)
135
+ parser.collect.to_a
136
+ end
137
+ end
138
+
139
+ module Tests
140
+ def test_usual_nginx_access_log
141
+ accesses = parse(join_lines(usual_log_line))
142
+ access = accesses.first
143
+ assert_equal(usual_log_entry, access)
144
+ end
145
+
146
+ def test_no_access_log
147
+ accesses = parse(join_lines())
148
+ assert_equal([], accesses)
149
+ end
150
+
151
+ def test_multiple_nginx_access_log
152
+ accesses = parse(join_lines(usual_log_line,
153
+ usual_log_line,
154
+ not_found_log_line))
155
+ assert_equal([usual_log_entry,
156
+ usual_log_entry,
157
+ not_found_log_entry],
158
+ accesses)
159
+ end
160
+
161
+ def test_reversed_nginx_access_log
162
+ accesses = reversed_parse(join_lines(usual_log_line,
163
+ usual_log_line,
164
+ not_found_log_line))
165
+ assert_equal([usual_log_entry,
166
+ usual_log_entry,
167
+ not_found_log_entry].reverse,
168
+ accesses)
169
+ end
170
+
171
+ def test_bad_nginx_access_log
172
+ assert_raise(Racknga::NginxAccessLogParser::FormatError) do
173
+ parse(join_lines(bad_log_line))
174
+ end
175
+ end
176
+
177
+ def test_invalid_utf8_log_line_ignored
178
+ accesses = parse(join_lines(valid_utf8_log_line,
179
+ invalid_utf8_log_line,
180
+ valid_utf8_log_line))
181
+ assert_equal([valid_utf8_log_entry,
182
+ valid_utf8_log_entry],
183
+ accesses)
184
+ end
185
+ end
186
+
187
+ class CombinedLogTest < Test::Unit::TestCase
188
+ include Environment
189
+ include Data
190
+ include Tests
191
+
192
+ def runtime
193
+ nil
194
+ end
195
+
196
+ def request_time
197
+ nil
198
+ end
199
+ end
200
+
201
+ class CombinedWithTimeLogTest < Test::Unit::TestCase
202
+ include Environment
203
+ include Data
204
+ include Tests
205
+
206
+ def runtime
207
+ 0.000573
208
+ end
209
+
210
+ def request_time
211
+ 0.001
212
+ end
213
+ end
214
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: racknga
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
5
- prerelease: false
4
+ hash: 63
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kouhei Sutou
@@ -15,13 +15,24 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-11 00:00:00 +09:00
19
- default_executable:
18
+ date: 2011-08-06 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
22
30
  name: rroonga
23
31
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
25
36
  none: false
26
37
  requirements:
27
38
  - - ">="
@@ -30,12 +41,26 @@ dependencies:
30
41
  segments:
31
42
  - 0
32
43
  version: "0"
44
+ name: rack
45
+ prerelease: false
33
46
  type: :runtime
34
- version_requirements: *id001
47
+ requirement: *id002
35
48
  - !ruby/object:Gem::Dependency
36
- name: rack
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ name: test-unit
37
59
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
60
+ type: :development
61
+ requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
39
64
  none: false
40
65
  requirements:
41
66
  - - ">="
@@ -44,94 +69,113 @@ dependencies:
44
69
  segments:
45
70
  - 0
46
71
  version: "0"
47
- type: :runtime
48
- version_requirements: *id002
72
+ name: test-unit-notify
73
+ prerelease: false
74
+ type: :development
75
+ requirement: *id004
49
76
  - !ruby/object:Gem::Dependency
50
- name: rubyforge
77
+ version_requirements: &id005 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ name: test-unit-capybara
51
87
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
88
+ type: :development
89
+ requirement: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ version_requirements: &id006 !ruby/object:Gem::Requirement
53
92
  none: false
54
93
  requirements:
55
94
  - - ">="
56
95
  - !ruby/object:Gem::Version
57
- hash: 7
96
+ hash: 3
58
97
  segments:
59
- - 2
60
98
  - 0
61
- - 4
62
- version: 2.0.4
99
+ version: "0"
100
+ name: rake
101
+ prerelease: false
63
102
  type: :development
64
- version_requirements: *id003
103
+ requirement: *id006
65
104
  - !ruby/object:Gem::Dependency
66
- name: hoe
105
+ version_requirements: &id007 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ name: jeweler
67
115
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
116
+ type: :development
117
+ requirement: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ version_requirements: &id008 !ruby/object:Gem::Requirement
69
120
  none: false
70
121
  requirements:
71
122
  - - ">="
72
123
  - !ruby/object:Gem::Version
73
- hash: 19
124
+ hash: 3
74
125
  segments:
75
- - 2
76
- - 6
77
- - 2
78
- version: 2.6.2
126
+ - 0
127
+ version: "0"
128
+ name: yard
129
+ prerelease: false
79
130
  type: :development
80
- version_requirements: *id004
81
- description: |
82
- * rroonga: http://groonga.rubyforge.org/
83
- * Rack: http://rack.rubyforge.org/
84
-
131
+ requirement: *id008
132
+ description: Racknga is a Rack middlewares that uses rroonga features.
85
133
  email:
86
- - groonga-users-en@rubyforge.org
87
- - groonga-dev@lists.sourceforge.jp
134
+ - kou@clear-code.com
88
135
  executables: []
89
136
 
90
137
  extensions: []
91
138
 
92
139
  extra_rdoc_files:
93
- - NEWS.rdoc
94
- - NEWS.ja.rdoc
95
- - README.ja.rdoc
96
- - README.rdoc
140
+ - README.textile
97
141
  files:
98
142
  - AUTHORS
99
- - NEWS.ja.rdoc
100
- - NEWS.rdoc
101
- - README.ja.rdoc
102
- - README.rdoc
143
+ - Gemfile
144
+ - README.textile
103
145
  - Rakefile
104
- - html/footer.html.erb
105
- - html/head.html.erb
106
- - html/header.html.erb
146
+ - doc/text//news.textile
147
+ - lib/racknga.rb
107
148
  - lib/racknga/cache_database.rb
108
149
  - lib/racknga/exception_mail_notifier.rb
109
150
  - lib/racknga/log_database.rb
110
151
  - lib/racknga/middleware/cache.rb
111
152
  - lib/racknga/middleware/deflater.rb
112
153
  - lib/racknga/middleware/exception_notifier.rb
154
+ - lib/racknga/middleware/instance_name.rb
113
155
  - lib/racknga/middleware/jsonp.rb
114
156
  - lib/racknga/middleware/log.rb
115
157
  - lib/racknga/middleware/range.rb
158
+ - lib/racknga/nginx_access_log_parser.rb
159
+ - lib/racknga/reverse_line_reader.rb
116
160
  - lib/racknga/utils.rb
117
161
  - lib/racknga/version.rb
118
162
  - lib/racknga/will_paginate.rb
119
- - lib/racknga.rb
120
- - munin/plugins/passenger_domain_
163
+ - license/lgpl-2.1.txt
164
+ - munin/plugins/passenger_application_
121
165
  - munin/plugins/passenger_status
122
- - test/fixtures/rabbit-theme-change.ogv
123
- - test/racknga-test-utils.rb
124
- - test/run-test.rb
125
166
  - test/test-middleware-jsonp.rb
167
+ - test/racknga-test-utils.rb
126
168
  - test/test-middleware-range.rb
127
- has_rdoc: true
169
+ - test/run-test.rb
170
+ - test/test-middleware-instance-name.rb
171
+ - test/test-middleware-cache.rb
172
+ - test/test-nginx-log-parser.rb
128
173
  homepage: http://groonga.rubyforge.org/
129
174
  licenses:
130
- - LGPL 2.1 or later
175
+ - LGPLv2.1 or later
131
176
  post_install_message:
132
- rdoc_options:
133
- - --main
134
- - README.ja.rdoc
177
+ rdoc_options: []
178
+
135
179
  require_paths:
136
180
  - lib
137
181
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -155,9 +199,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
199
  requirements: []
156
200
 
157
201
  rubyforge_project: groonga
158
- rubygems_version: 1.3.7
202
+ rubygems_version: 1.7.2
159
203
  signing_key:
160
204
  specification_version: 3
161
- summary: Rack middlewares that uses rroonga features.
205
+ summary: A Rack middleware collection for rroonga features.
162
206
  test_files:
207
+ - test/test-middleware-jsonp.rb
208
+ - test/racknga-test-utils.rb
209
+ - test/test-middleware-range.rb
163
210
  - test/run-test.rb
211
+ - test/test-middleware-instance-name.rb
212
+ - test/test-middleware-cache.rb
213
+ - test/test-nginx-log-parser.rb
data/NEWS.ja.rdoc DELETED
@@ -1,16 +0,0 @@
1
- = お知らせ
2
-
3
- == 0.9.1: 2010-11-11
4
-
5
- * キャッシュの正当性チェックを強化。
6
- * User-Agent毎のキャッシュをサポート。
7
- * JSONPをサポートするミドルウェアを追加。
8
- * HTTPのRangeをサポートするミドルウェアを追加。
9
- * groongaデータベースにアクセスログを記録するミドルウェアを追加。
10
- * Passengerの状態を視覚化するMuninプラグインを追加。
11
- * ライセンスをLGPLv2.1からLGPLv2.1 or laterに変更。
12
- * will_paginate対応。
13
-
14
- == 0.9.0: 2010-07-04
15
-
16
- * 最初のリリース!
data/NEWS.rdoc DELETED
@@ -1,9 +0,0 @@
1
- = NEWS
2
-
3
- == 0.9.1: 2010-11-11
4
-
5
- * Supported will_paginate.
6
-
7
- == 0.9.0: 2010-07-04
8
-
9
- * Initial release!
data/README.ja.rdoc DELETED
@@ -1,80 +0,0 @@
1
- = はじめに
2
-
3
- == 名前
4
-
5
- racknga(らくんが)
6
-
7
- == 説明
8
-
9
- rroongaの機能を利用したRackのミドルウェアとrroongaの機能は利
10
- 用してませんが役に立つミドルウェアを提供します。
11
-
12
- * rroonga: http://groonga.rubyforge.org/
13
- * Rack: http://rack.rubyforge.org/
14
-
15
- == 作者
16
-
17
- Kouhei Sutou:: <tt><kou@clear-code.com></tt>
18
-
19
- == ライセンス
20
-
21
- LGPL 2.1またはそれ以降のバージョンです。詳しくは
22
- license/lgpl-2.1.txtを見てください。
23
-
24
- (コントリビュートされたパッチなども含み、Kouhei Sutouが
25
- ライセンスを変更する権利を持ちます。)
26
-
27
- == 依存ソフトウェア
28
-
29
- * Ruby >= 1.9.1
30
- * rroonga
31
- * Rack
32
-
33
- === あるとよいソフトウェア
34
-
35
- * jpmobile
36
- * will_paginate
37
-
38
- == インストール
39
-
40
- % sudo gem install racknga
41
-
42
- == メーリングリスト
43
-
44
- 質問、要望、バグ報告などはgroongaのMLにお願いします。
45
-
46
- http://lists.sourceforge.jp/mailman/listinfo/groonga-dev
47
-
48
- == ドキュメント
49
-
50
- RackngaにはRackアプリケーションに有用なミドルウェアをたくさん
51
- 提供しています。ここでは、オプションなど詳細な情報は
52
- http://groonga.rubyforge.org/racknga/ を参照してください。
53
-
54
- === Racknga::Middleware::Cache
55
-
56
- ...
57
-
58
- === Racknga::Middleware::Deflater
59
-
60
- ...
61
-
62
- === Racknga::Middleware::ExceptionNotifier
63
-
64
- ...
65
-
66
- === Racknga::Middleware::JSONP
67
-
68
- ...
69
-
70
- === Racknga::Middleware::Range
71
-
72
- ...
73
-
74
- === Racknga::Middleware::Log
75
-
76
- ...
77
-
78
- == 感謝
79
-
80
- * ...
data/README.rdoc DELETED
@@ -1,51 +0,0 @@
1
- = README
2
-
3
- == Name
4
-
5
- racknga
6
-
7
- == Description
8
-
9
- Rack middlewares that uses rroonga features.
10
-
11
- * rroonga: http://groonga.rubyforge.org/
12
- * Rack: http://rack.rubyforge.org/
13
-
14
- == Authors
15
-
16
- Kouhei Sutou:: <tt><kou@clear-code.com></tt>
17
-
18
- == License
19
-
20
- LGPL 2.1 or later. See license/lgpl-2.1.txt for details.
21
-
22
- (Kouhei Sutou has a right to change the license
23
- inclidng contributed patches.)
24
-
25
- == Dependencies
26
-
27
- * Ruby >= 1.9.1
28
- * rroonga
29
- * Rack
30
-
31
- == Suggested libraries
32
-
33
- * will_paginate
34
-
35
- == Install
36
-
37
- % sudo gem install racknga
38
-
39
- == Documents
40
-
41
- Japanese only. Sorry.
42
-
43
- http://groonga.rubyforge.org/racknga/
44
-
45
- == Mailing list
46
-
47
- http://rubyforge.org/mailman/listinfo/groonga-users-en
48
-
49
- == Thanks
50
-
51
- * ...
data/html/footer.html.erb DELETED
@@ -1,33 +0,0 @@
1
- </div>
2
-
3
- <div class="sponsors">
4
- <p id="sponsor-rubyforge">
5
- <a href="http://rubyforge.org/projects/groonga/">
6
- <img src="/rubyforge.png" width="120" height="24" border="0" alt="Ruby/groongaプロジェクトはRubyForge.orgにホスティングしてもらっています。" />
7
- </a>
8
- </p>
9
- <p id="sponsor-github">
10
- <a href="http://github.com/ranguba/">
11
- ラングバプロジェクトはGitHubにホスティングしてもらっています。
12
- </a>
13
- </p>
14
- <p id="sponsor-tango">
15
- <a href="http://tango.freedesktop.org/">
16
- <img width="120" height="53" border="0" alt="Tango Desktop Projectのアイコンを利用しています。" src="/tango-logo.png" />
17
- </a>
18
- </p>
19
-
20
- <!-- Piwik -->
21
- <a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">
22
- <script type="text/javascript">
23
- var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.clear-code.com/piwik/" : "http://www.clear-code.com/piwik/");
24
- document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
25
- </script><script type="text/javascript">
26
- piwik_action_name = '';
27
- piwik_idsite = 2;
28
- piwik_url = pkBaseURL + "piwik.php";
29
- piwik_log(piwik_action_name, piwik_idsite, piwik_url);
30
- </script>
31
- <object><noscript><p>Web analytics <img src="http://www.clear-code.com/piwik/piwik.php?idsite=2" style="border:0" alt=""/></p></noscript></object></a>
32
- <!-- End Piwik Tag -->
33
- </div>
data/html/head.html.erb DELETED
@@ -1,4 +0,0 @@
1
- <link rel="stylesheet" href="/ranguba.css" type="text/css" />
2
- <link rel="shortcut icon" href="/favicon.ico" />
3
- <link rel="icon" href="/favicon.png" />
4
- <title><%= h(title) %> - ラングバ</title>
data/html/header.html.erb DELETED
@@ -1,17 +0,0 @@
1
- <div class="header">
2
- <div class="title">
3
- <a href="/">
4
- <span class="title"><%= h(title) %></span>
5
- <span class="title-separator">-</span>
6
- <span class="title-project">ラングバ</span>
7
- </a>
8
- </div>
9
- <ul class="menu">
10
- <li id="menu-reference"><a href="/rroonga/">リファレンスマニュアル</a></li>
11
- <li id="menu-tutorial"><a href="/rroonga/text/TUTORIAL_ja_rdoc.html">チュートリアル</a></li>
12
- <li id="menu-install"><a href="/#install-rroonga">インストール</a></li>
13
- <li id="menu-developer"><a href="/developer.html">開発者向け情報</a></li>
14
- </ul>
15
- </div>
16
-
17
- <div class="content">
Binary file