egalite 0.0.7 → 1.0.0

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.
Files changed (93) hide show
  1. data/README.md +19 -0
  2. data/lib/egalite/version.rb +1 -1
  3. data/lib/egalite.rb +11 -2
  4. data/test/test_auth.rb +1 -2
  5. data/test/test_blank.rb +2 -3
  6. data/test/test_errorconsole.rb +5 -5
  7. data/test/test_keitai.rb +2 -2
  8. data/test/test_m17n.rb +1 -3
  9. data/test/test_template.rb +11 -0
  10. metadata +4 -87
  11. data/auth/basic.rb +0 -32
  12. data/blank.rb +0 -53
  13. data/egalite.rb +0 -742
  14. data/errorconsole.rb +0 -77
  15. data/helper.rb +0 -251
  16. data/keitai/keitai.rb +0 -107
  17. data/keitai/ketai.rb +0 -11
  18. data/keitai/rack/ketai/carrier/abstract.rb +0 -131
  19. data/keitai/rack/ketai/carrier/au.rb +0 -78
  20. data/keitai/rack/ketai/carrier/docomo.rb +0 -80
  21. data/keitai/rack/ketai/carrier/emoji/ausjisstrtoemojiid.rb +0 -1391
  22. data/keitai/rack/ketai/carrier/emoji/docomosjisstrtoemojiid.rb +0 -759
  23. data/keitai/rack/ketai/carrier/emoji/emojidata.rb +0 -836
  24. data/keitai/rack/ketai/carrier/emoji/softbankutf8strtoemojiid.rb +0 -1119
  25. data/keitai/rack/ketai/carrier/emoji/softbankwebcodetoutf8str.rb +0 -499
  26. data/keitai/rack/ketai/carrier/iphone.rb +0 -8
  27. data/keitai/rack/ketai/carrier/softbank.rb +0 -82
  28. data/keitai/rack/ketai/carrier.rb +0 -17
  29. data/keitai/rack/ketai/middleware.rb +0 -24
  30. data/m17n.rb +0 -193
  31. data/rack/auth/abstract/handler.rb +0 -37
  32. data/rack/auth/abstract/request.rb +0 -37
  33. data/rack/auth/basic.rb +0 -58
  34. data/rack/auth/digest/md5.rb +0 -124
  35. data/rack/auth/digest/nonce.rb +0 -51
  36. data/rack/auth/digest/params.rb +0 -55
  37. data/rack/auth/digest/request.rb +0 -40
  38. data/rack/builder.rb +0 -80
  39. data/rack/cascade.rb +0 -41
  40. data/rack/chunked.rb +0 -49
  41. data/rack/commonlogger.rb +0 -49
  42. data/rack/conditionalget.rb +0 -47
  43. data/rack/config.rb +0 -15
  44. data/rack/content_length.rb +0 -29
  45. data/rack/content_type.rb +0 -23
  46. data/rack/deflater.rb +0 -96
  47. data/rack/directory.rb +0 -157
  48. data/rack/etag.rb +0 -32
  49. data/rack/file.rb +0 -92
  50. data/rack/handler/cgi.rb +0 -62
  51. data/rack/handler/evented_mongrel.rb +0 -8
  52. data/rack/handler/fastcgi.rb +0 -89
  53. data/rack/handler/lsws.rb +0 -63
  54. data/rack/handler/mongrel.rb +0 -90
  55. data/rack/handler/scgi.rb +0 -59
  56. data/rack/handler/swiftiplied_mongrel.rb +0 -8
  57. data/rack/handler/thin.rb +0 -18
  58. data/rack/handler/webrick.rb +0 -73
  59. data/rack/handler.rb +0 -88
  60. data/rack/head.rb +0 -19
  61. data/rack/lint.rb +0 -567
  62. data/rack/lobster.rb +0 -65
  63. data/rack/lock.rb +0 -16
  64. data/rack/logger.rb +0 -20
  65. data/rack/methodoverride.rb +0 -27
  66. data/rack/mime.rb +0 -208
  67. data/rack/mock.rb +0 -190
  68. data/rack/nulllogger.rb +0 -18
  69. data/rack/recursive.rb +0 -61
  70. data/rack/reloader.rb +0 -109
  71. data/rack/request.rb +0 -273
  72. data/rack/response.rb +0 -150
  73. data/rack/rewindable_input.rb +0 -103
  74. data/rack/runtime.rb +0 -27
  75. data/rack/sendfile.rb +0 -144
  76. data/rack/server.rb +0 -271
  77. data/rack/session/abstract/id.rb +0 -140
  78. data/rack/session/cookie.rb +0 -90
  79. data/rack/session/memcache.rb +0 -119
  80. data/rack/session/pool.rb +0 -100
  81. data/rack/showexceptions.rb +0 -349
  82. data/rack/showstatus.rb +0 -106
  83. data/rack/static.rb +0 -38
  84. data/rack/urlmap.rb +0 -55
  85. data/rack/utils.rb +0 -662
  86. data/rack.rb +0 -81
  87. data/route.rb +0 -231
  88. data/sendmail.rb +0 -222
  89. data/sequel_helper.rb +0 -20
  90. data/session.rb +0 -132
  91. data/stringify_hash.rb +0 -63
  92. data/support.rb +0 -35
  93. data/template.rb +0 -287
data/rack/cascade.rb DELETED
@@ -1,41 +0,0 @@
1
- module Rack
2
- # Rack::Cascade tries an request on several apps, and returns the
3
- # first response that is not 404 (or in a list of configurable
4
- # status codes).
5
-
6
- class Cascade
7
- NotFound = [404, {}, []]
8
-
9
- attr_reader :apps
10
-
11
- def initialize(apps, catch=404)
12
- @apps = []; @has_app = {}
13
- apps.each { |app| add app }
14
-
15
- @catch = {}
16
- [*catch].each { |status| @catch[status] = true }
17
- end
18
-
19
- def call(env)
20
- result = NotFound
21
-
22
- @apps.each do |app|
23
- result = app.call(env)
24
- break unless @catch.include?(result[0].to_i)
25
- end
26
-
27
- result
28
- end
29
-
30
- def add app
31
- @has_app[app] = true
32
- @apps << app
33
- end
34
-
35
- def include? app
36
- @has_app.include? app
37
- end
38
-
39
- alias_method :<<, :add
40
- end
41
- end
data/rack/chunked.rb DELETED
@@ -1,49 +0,0 @@
1
- require 'rack/utils'
2
-
3
- module Rack
4
-
5
- # Middleware that applies chunked transfer encoding to response bodies
6
- # when the response does not include a Content-Length header.
7
- class Chunked
8
- include Rack::Utils
9
-
10
- def initialize(app)
11
- @app = app
12
- end
13
-
14
- def call(env)
15
- status, headers, body = @app.call(env)
16
- headers = HeaderHash.new(headers)
17
-
18
- if env['HTTP_VERSION'] == 'HTTP/1.0' ||
19
- STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
20
- headers['Content-Length'] ||
21
- headers['Transfer-Encoding']
22
- [status, headers, body]
23
- else
24
- dup.chunk(status, headers, body)
25
- end
26
- end
27
-
28
- def chunk(status, headers, body)
29
- @body = body
30
- headers.delete('Content-Length')
31
- headers['Transfer-Encoding'] = 'chunked'
32
- [status, headers, self]
33
- end
34
-
35
- def each
36
- term = "\r\n"
37
- @body.each do |chunk|
38
- size = bytesize(chunk)
39
- next if size == 0
40
- yield [size.to_s(16), term, chunk, term].join
41
- end
42
- yield ["0", term, "", term].join
43
- end
44
-
45
- def close
46
- @body.close if @body.respond_to?(:close)
47
- end
48
- end
49
- end
data/rack/commonlogger.rb DELETED
@@ -1,49 +0,0 @@
1
- module Rack
2
- # Rack::CommonLogger forwards every request to an +app+ given, and
3
- # logs a line in the Apache common log format to the +logger+, or
4
- # rack.errors by default.
5
- class CommonLogger
6
- # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
7
- # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
8
- # %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
9
- FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}
10
-
11
- def initialize(app, logger=nil)
12
- @app = app
13
- @logger = logger
14
- end
15
-
16
- def call(env)
17
- began_at = Time.now
18
- status, header, body = @app.call(env)
19
- header = Utils::HeaderHash.new(header)
20
- log(env, status, header, began_at)
21
- [status, header, body]
22
- end
23
-
24
- private
25
-
26
- def log(env, status, header, began_at)
27
- now = Time.now
28
- length = extract_content_length(header)
29
-
30
- logger = @logger || env['rack.errors']
31
- logger.write FORMAT % [
32
- env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
33
- env["REMOTE_USER"] || "-",
34
- now.strftime("%d/%b/%Y %H:%M:%S"),
35
- env["REQUEST_METHOD"],
36
- env["PATH_INFO"],
37
- env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
38
- env["HTTP_VERSION"],
39
- status.to_s[0..3],
40
- length,
41
- now - began_at ]
42
- end
43
-
44
- def extract_content_length(headers)
45
- value = headers['Content-Length'] or return '-'
46
- value.to_s == '0' ? '-' : value
47
- end
48
- end
49
- end
@@ -1,47 +0,0 @@
1
- require 'rack/utils'
2
-
3
- module Rack
4
-
5
- # Middleware that enables conditional GET using If-None-Match and
6
- # If-Modified-Since. The application should set either or both of the
7
- # Last-Modified or Etag response headers according to RFC 2616. When
8
- # either of the conditions is met, the response body is set to be zero
9
- # length and the response status is set to 304 Not Modified.
10
- #
11
- # Applications that defer response body generation until the body's each
12
- # message is received will avoid response body generation completely when
13
- # a conditional GET matches.
14
- #
15
- # Adapted from Michael Klishin's Merb implementation:
16
- # http://github.com/wycats/merb-core/tree/master/lib/merb-core/rack/middleware/conditional_get.rb
17
- class ConditionalGet
18
- def initialize(app)
19
- @app = app
20
- end
21
-
22
- def call(env)
23
- return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD'])
24
-
25
- status, headers, body = @app.call(env)
26
- headers = Utils::HeaderHash.new(headers)
27
- if etag_matches?(env, headers) || modified_since?(env, headers)
28
- status = 304
29
- headers.delete('Content-Type')
30
- headers.delete('Content-Length')
31
- body = []
32
- end
33
- [status, headers, body]
34
- end
35
-
36
- private
37
- def etag_matches?(env, headers)
38
- etag = headers['Etag'] and etag == env['HTTP_IF_NONE_MATCH']
39
- end
40
-
41
- def modified_since?(env, headers)
42
- last_modified = headers['Last-Modified'] and
43
- last_modified == env['HTTP_IF_MODIFIED_SINCE']
44
- end
45
- end
46
-
47
- end
data/rack/config.rb DELETED
@@ -1,15 +0,0 @@
1
- module Rack
2
- # Rack::Config modifies the environment using the block given during
3
- # initialization.
4
- class Config
5
- def initialize(app, &block)
6
- @app = app
7
- @block = block
8
- end
9
-
10
- def call(env)
11
- @block.call(env)
12
- @app.call(env)
13
- end
14
- end
15
- end
@@ -1,29 +0,0 @@
1
- require 'rack/utils'
2
-
3
- module Rack
4
- # Sets the Content-Length header on responses with fixed-length bodies.
5
- class ContentLength
6
- include Rack::Utils
7
-
8
- def initialize(app)
9
- @app = app
10
- end
11
-
12
- def call(env)
13
- status, headers, body = @app.call(env)
14
- headers = HeaderHash.new(headers)
15
-
16
- if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
17
- !headers['Content-Length'] &&
18
- !headers['Transfer-Encoding'] &&
19
- (body.respond_to?(:to_ary) || body.respond_to?(:to_str))
20
-
21
- body = [body] if body.respond_to?(:to_str) # rack 0.4 compat
22
- length = body.to_ary.inject(0) { |len, part| len + bytesize(part) }
23
- headers['Content-Length'] = length.to_s
24
- end
25
-
26
- [status, headers, body]
27
- end
28
- end
29
- end
data/rack/content_type.rb DELETED
@@ -1,23 +0,0 @@
1
- require 'rack/utils'
2
-
3
- module Rack
4
-
5
- # Sets the Content-Type header on responses which don't have one.
6
- #
7
- # Builder Usage:
8
- # use Rack::ContentType, "text/plain"
9
- #
10
- # When no content type argument is provided, "text/html" is assumed.
11
- class ContentType
12
- def initialize(app, content_type = "text/html")
13
- @app, @content_type = app, content_type
14
- end
15
-
16
- def call(env)
17
- status, headers, body = @app.call(env)
18
- headers = Utils::HeaderHash.new(headers)
19
- headers['Content-Type'] ||= @content_type
20
- [status, headers, body]
21
- end
22
- end
23
- end
data/rack/deflater.rb DELETED
@@ -1,96 +0,0 @@
1
- require "zlib"
2
- require "stringio"
3
- require "time" # for Time.httpdate
4
- require 'rack/utils'
5
-
6
- module Rack
7
- class Deflater
8
- def initialize(app)
9
- @app = app
10
- end
11
-
12
- def call(env)
13
- status, headers, body = @app.call(env)
14
- headers = Utils::HeaderHash.new(headers)
15
-
16
- # Skip compressing empty entity body responses and responses with
17
- # no-transform set.
18
- if Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
19
- headers['Cache-Control'].to_s =~ /\bno-transform\b/
20
- return [status, headers, body]
21
- end
22
-
23
- request = Request.new(env)
24
-
25
- encoding = Utils.select_best_encoding(%w(gzip deflate identity),
26
- request.accept_encoding)
27
-
28
- # Set the Vary HTTP header.
29
- vary = headers["Vary"].to_s.split(",").map { |v| v.strip }
30
- unless vary.include?("*") || vary.include?("Accept-Encoding")
31
- headers["Vary"] = vary.push("Accept-Encoding").join(",")
32
- end
33
-
34
- case encoding
35
- when "gzip"
36
- headers['Content-Encoding'] = "gzip"
37
- headers.delete('Content-Length')
38
- mtime = headers.key?("Last-Modified") ?
39
- Time.httpdate(headers["Last-Modified"]) : Time.now
40
- [status, headers, GzipStream.new(body, mtime)]
41
- when "deflate"
42
- headers['Content-Encoding'] = "deflate"
43
- headers.delete('Content-Length')
44
- [status, headers, DeflateStream.new(body)]
45
- when "identity"
46
- [status, headers, body]
47
- when nil
48
- message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found."
49
- [406, {"Content-Type" => "text/plain", "Content-Length" => message.length.to_s}, [message]]
50
- end
51
- end
52
-
53
- class GzipStream
54
- def initialize(body, mtime)
55
- @body = body
56
- @mtime = mtime
57
- end
58
-
59
- def each(&block)
60
- @writer = block
61
- gzip =::Zlib::GzipWriter.new(self)
62
- gzip.mtime = @mtime
63
- @body.each { |part| gzip.write(part) }
64
- @body.close if @body.respond_to?(:close)
65
- gzip.close
66
- @writer = nil
67
- end
68
-
69
- def write(data)
70
- @writer.call(data)
71
- end
72
- end
73
-
74
- class DeflateStream
75
- DEFLATE_ARGS = [
76
- Zlib::DEFAULT_COMPRESSION,
77
- # drop the zlib header which causes both Safari and IE to choke
78
- -Zlib::MAX_WBITS,
79
- Zlib::DEF_MEM_LEVEL,
80
- Zlib::DEFAULT_STRATEGY
81
- ]
82
-
83
- def initialize(body)
84
- @body = body
85
- end
86
-
87
- def each
88
- deflater = ::Zlib::Deflate.new(*DEFLATE_ARGS)
89
- @body.each { |part| yield deflater.deflate(part) }
90
- @body.close if @body.respond_to?(:close)
91
- yield deflater.finish
92
- nil
93
- end
94
- end
95
- end
96
- end
data/rack/directory.rb DELETED
@@ -1,157 +0,0 @@
1
- require 'time'
2
- require 'rack/utils'
3
- require 'rack/mime'
4
-
5
- module Rack
6
- # Rack::Directory serves entries below the +root+ given, according to the
7
- # path info of the Rack request. If a directory is found, the file's contents
8
- # will be presented in an html based index. If a file is found, the env will
9
- # be passed to the specified +app+.
10
- #
11
- # If +app+ is not specified, a Rack::File of the same +root+ will be used.
12
-
13
- class Directory
14
- DIR_FILE = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>"
15
- DIR_PAGE = <<-PAGE
16
- <html><head>
17
- <title>%s</title>
18
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
19
- <style type='text/css'>
20
- table { width:100%%; }
21
- .name { text-align:left; }
22
- .size, .mtime { text-align:right; }
23
- .type { width:11em; }
24
- .mtime { width:15em; }
25
- </style>
26
- </head><body>
27
- <h1>%s</h1>
28
- <hr />
29
- <table>
30
- <tr>
31
- <th class='name'>Name</th>
32
- <th class='size'>Size</th>
33
- <th class='type'>Type</th>
34
- <th class='mtime'>Last Modified</th>
35
- </tr>
36
- %s
37
- </table>
38
- <hr />
39
- </body></html>
40
- PAGE
41
-
42
- attr_reader :files
43
- attr_accessor :root, :path
44
-
45
- def initialize(root, app=nil)
46
- @root = F.expand_path(root)
47
- @app = app || Rack::File.new(@root)
48
- end
49
-
50
- def call(env)
51
- dup._call(env)
52
- end
53
-
54
- F = ::File
55
-
56
- def _call(env)
57
- @env = env
58
- @script_name = env['SCRIPT_NAME']
59
- @path_info = Utils.unescape(env['PATH_INFO'])
60
-
61
- if forbidden = check_forbidden
62
- forbidden
63
- else
64
- @path = F.join(@root, @path_info)
65
- list_path
66
- end
67
- end
68
-
69
- def check_forbidden
70
- return unless @path_info.include? ".."
71
-
72
- body = "Forbidden\n"
73
- size = Rack::Utils.bytesize(body)
74
- return [403, {"Content-Type" => "text/plain",
75
- "Content-Length" => size.to_s,
76
- "X-Cascade" => "pass"}, [body]]
77
- end
78
-
79
- def list_directory
80
- @files = [['../','Parent Directory','','','']]
81
- glob = F.join(@path, '*')
82
-
83
- Dir[glob].sort.each do |node|
84
- stat = stat(node)
85
- next unless stat
86
- basename = F.basename(node)
87
- ext = F.extname(node)
88
-
89
- url = F.join(@script_name, @path_info, basename)
90
- size = stat.size
91
- type = stat.directory? ? 'directory' : Mime.mime_type(ext)
92
- size = stat.directory? ? '-' : filesize_format(size)
93
- mtime = stat.mtime.httpdate
94
- url << '/' if stat.directory?
95
- basename << '/' if stat.directory?
96
-
97
- @files << [ url, basename, size, type, mtime ]
98
- end
99
-
100
- return [ 200, {'Content-Type'=>'text/html; charset=utf-8'}, self ]
101
- end
102
-
103
- def stat(node, max = 10)
104
- F.stat(node)
105
- rescue Errno::ENOENT, Errno::ELOOP
106
- return nil
107
- end
108
-
109
- # TODO: add correct response if not readable, not sure if 404 is the best
110
- # option
111
- def list_path
112
- @stat = F.stat(@path)
113
-
114
- if @stat.readable?
115
- return @app.call(@env) if @stat.file?
116
- return list_directory if @stat.directory?
117
- else
118
- raise Errno::ENOENT, 'No such file or directory'
119
- end
120
-
121
- rescue Errno::ENOENT, Errno::ELOOP
122
- return entity_not_found
123
- end
124
-
125
- def entity_not_found
126
- body = "Entity not found: #{@path_info}\n"
127
- size = Rack::Utils.bytesize(body)
128
- return [404, {"Content-Type" => "text/plain",
129
- "Content-Length" => size.to_s,
130
- "X-Cascade" => "pass"}, [body]]
131
- end
132
-
133
- def each
134
- show_path = @path.sub(/^#{@root}/,'')
135
- files = @files.map{|f| DIR_FILE % f }*"\n"
136
- page = DIR_PAGE % [ show_path, show_path , files ]
137
- page.each_line{|l| yield l }
138
- end
139
-
140
- # Stolen from Ramaze
141
-
142
- FILESIZE_FORMAT = [
143
- ['%.1fT', 1 << 40],
144
- ['%.1fG', 1 << 30],
145
- ['%.1fM', 1 << 20],
146
- ['%.1fK', 1 << 10],
147
- ]
148
-
149
- def filesize_format(int)
150
- FILESIZE_FORMAT.each do |format, size|
151
- return format % (int.to_f / size) if int >= size
152
- end
153
-
154
- int.to_s + 'B'
155
- end
156
- end
157
- end
data/rack/etag.rb DELETED
@@ -1,32 +0,0 @@
1
- require 'digest/md5'
2
-
3
- module Rack
4
- # Automatically sets the ETag header on all String bodies
5
- class ETag
6
- def initialize(app)
7
- @app = app
8
- end
9
-
10
- def call(env)
11
- status, headers, body = @app.call(env)
12
-
13
- if !headers.has_key?('ETag')
14
- digest, body = digest_body(body)
15
- headers['ETag'] = %("#{digest}")
16
- end
17
-
18
- [status, headers, body]
19
- end
20
-
21
- private
22
- def digest_body(body)
23
- digest = Digest::MD5.new
24
- parts = []
25
- body.each do |part|
26
- digest << part
27
- parts << part
28
- end
29
- [digest.hexdigest, parts]
30
- end
31
- end
32
- end
data/rack/file.rb DELETED
@@ -1,92 +0,0 @@
1
- require 'time'
2
- require 'rack/utils'
3
- require 'rack/mime'
4
-
5
- module Rack
6
- # Rack::File serves files below the +root+ directory given, according to the
7
- # path info of the Rack request.
8
- # e.g. when Rack::File.new("/etc") is used, you can access 'passwd' file
9
- # as http://localhost:9292/passwd
10
- #
11
- # Handlers can detect if bodies are a Rack::File, and use mechanisms
12
- # like sendfile on the +path+.
13
-
14
- class File
15
- attr_accessor :root
16
- attr_accessor :path
17
-
18
- alias :to_path :path
19
-
20
- def initialize(root)
21
- @root = root
22
- end
23
-
24
- def call(env)
25
- dup._call(env)
26
- end
27
-
28
- F = ::File
29
-
30
- def _call(env)
31
- @path_info = Utils.unescape(env["PATH_INFO"])
32
- return forbidden if @path_info.include? ".."
33
-
34
- @path = F.join(@root, @path_info)
35
-
36
- begin
37
- if F.file?(@path) && F.readable?(@path)
38
- serving
39
- else
40
- raise Errno::EPERM
41
- end
42
- rescue SystemCallError
43
- not_found
44
- end
45
- end
46
-
47
- def forbidden
48
- body = "Forbidden\n"
49
- [403, {"Content-Type" => "text/plain",
50
- "Content-Length" => body.size.to_s,
51
- "X-Cascade" => "pass"},
52
- [body]]
53
- end
54
-
55
- # NOTE:
56
- # We check via File::size? whether this file provides size info
57
- # via stat (e.g. /proc files often don't), otherwise we have to
58
- # figure it out by reading the whole file into memory. And while
59
- # we're at it we also use this as body then.
60
-
61
- def serving
62
- if size = F.size?(@path)
63
- body = self
64
- else
65
- body = [F.read(@path)]
66
- size = Utils.bytesize(body.first)
67
- end
68
-
69
- [200, {
70
- "Last-Modified" => F.mtime(@path).httpdate,
71
- "Content-Type" => Mime.mime_type(F.extname(@path), 'text/plain'),
72
- "Content-Length" => size.to_s
73
- }, body]
74
- end
75
-
76
- def not_found
77
- body = "File not found: #{@path_info}\n"
78
- [404, {"Content-Type" => "text/plain",
79
- "Content-Length" => body.size.to_s,
80
- "X-Cascade" => "pass"},
81
- [body]]
82
- end
83
-
84
- def each
85
- F.open(@path, "rb") { |file|
86
- while part = file.read(8192)
87
- yield part
88
- end
89
- }
90
- end
91
- end
92
- end
data/rack/handler/cgi.rb DELETED
@@ -1,62 +0,0 @@
1
- require 'rack/content_length'
2
-
3
- module Rack
4
- module Handler
5
- class CGI
6
- def self.run(app, options=nil)
7
- $stdin.binmode
8
- serve app
9
- end
10
-
11
- def self.serve(app)
12
- app = ContentLength.new(app)
13
-
14
- env = ENV.to_hash
15
- env.delete "HTTP_CONTENT_LENGTH"
16
-
17
- env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
18
-
19
- env.update({"rack.version" => Rack::VERSION,
20
- "rack.input" => $stdin,
21
- "rack.errors" => $stderr,
22
-
23
- "rack.multithread" => false,
24
- "rack.multiprocess" => true,
25
- "rack.run_once" => true,
26
-
27
- "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
28
- })
29
-
30
- env["QUERY_STRING"] ||= ""
31
- env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
32
- env["REQUEST_PATH"] ||= "/"
33
-
34
- status, headers, body = app.call(env)
35
- begin
36
- send_headers status, headers
37
- send_body body
38
- ensure
39
- body.close if body.respond_to? :close
40
- end
41
- end
42
-
43
- def self.send_headers(status, headers)
44
- $stdout.print "Status: #{status}\r\n"
45
- headers.each { |k, vs|
46
- vs.split("\n").each { |v|
47
- $stdout.print "#{k}: #{v}\r\n"
48
- }
49
- }
50
- $stdout.print "\r\n"
51
- $stdout.flush
52
- end
53
-
54
- def self.send_body(body)
55
- body.each { |part|
56
- $stdout.print part
57
- $stdout.flush
58
- }
59
- end
60
- end
61
- end
62
- end