Instiki 0.16.5

Update to Rails 2.3.2 (the stable Rails 2.3 release).
Add audio/speex support
Update CHANGELOG
Bump version number
This commit is contained in:
Jacques Distler 2009-03-16 09:55:30 -05:00
parent 801d307405
commit e2ccdfd812
264 changed files with 4850 additions and 1906 deletions

View file

@ -556,7 +556,7 @@ module HTML
end
# Attribute value.
next if statement.sub!(/^\[\s*([[:alpha:]][\w\-]*)\s*((?:[~|^$*])?=)?\s*('[^']*'|"[^*]"|[^\]]*)\s*\]/) do |match|
next if statement.sub!(/^\[\s*([[:alpha:]][\w\-:]*)\s*((?:[~|^$*])?=)?\s*('[^']*'|"[^*]"|[^\]]*)\s*\]/) do |match|
name, equality, value = $1, $2, $3
if value == "?"
value = values.shift

View file

@ -23,14 +23,16 @@ module Rack
# Return the Rack release as a dotted string.
def self.release
"0.4"
"1.0 bundled"
end
autoload :Builder, "rack/builder"
autoload :Cascade, "rack/cascade"
autoload :Chunked, "rack/chunked"
autoload :CommonLogger, "rack/commonlogger"
autoload :ConditionalGet, "rack/conditionalget"
autoload :ContentLength, "rack/content_length"
autoload :ContentType, "rack/content_type"
autoload :File, "rack/file"
autoload :Deflater, "rack/deflater"
autoload :Directory, "rack/directory"

View file

@ -8,8 +8,8 @@ module Rack
attr_accessor :realm
def initialize(app, &authenticator)
@app, @authenticator = app, authenticator
def initialize(app, realm=nil, &authenticator)
@app, @realm, @authenticator = app, realm, authenticator
end

View file

@ -21,7 +21,7 @@ module Rack
attr_writer :passwords_hashed
def initialize(app)
def initialize(*args)
super
@passwords_hashed = nil
end

View file

@ -8,7 +8,7 @@ module Rack
class Request < Auth::AbstractRequest
def method
@env['REQUEST_METHOD']
@env['rack.methodoverride.original_method'] || @env['REQUEST_METHOD']
end
def digest?

View file

@ -34,11 +34,7 @@ module Rack
end
def use(middleware, *args, &block)
@ins << if block_given?
lambda { |app| middleware.new(app, *args, &block) }
else
lambda { |app| middleware.new(app, *args) }
end
@ins << lambda { |app| middleware.new(app, *args, &block) }
end
def run(app)

View file

@ -0,0 +1,49 @@
require 'rack/utils'
module Rack
# Middleware that applies chunked transfer encoding to response bodies
# when the response does not include a Content-Length header.
class Chunked
include Rack::Utils
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers = HeaderHash.new(headers)
if env['HTTP_VERSION'] == 'HTTP/1.0' ||
STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
headers['Content-Length'] ||
headers['Transfer-Encoding']
[status, headers.to_hash, body]
else
dup.chunk(status, headers, body)
end
end
def chunk(status, headers, body)
@body = body
headers.delete('Content-Length')
headers['Transfer-Encoding'] = 'chunked'
[status, headers.to_hash, self]
end
def each
term = "\r\n"
@body.each do |chunk|
size = bytesize(chunk)
next if size == 0
yield [size.to_s(16), term, chunk, term].join
end
yield ["0", term, "", term].join
end
def close
@body.close if @body.respond_to?(:close)
end
end
end

View file

@ -3,21 +3,23 @@ require 'rack/utils'
module Rack
# Sets the Content-Length header on responses with fixed-length bodies.
class ContentLength
include Rack::Utils
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers = Utils::HeaderHash.new(headers)
headers = HeaderHash.new(headers)
if !Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
!headers['Content-Length'] &&
!headers['Transfer-Encoding'] &&
(body.respond_to?(:to_ary) || body.respond_to?(:to_str))
body = [body] if body.respond_to?(:to_str) # rack 0.4 compat
length = body.to_ary.inject(0) { |len, part| len + part.length }
length = body.to_ary.inject(0) { |len, part| len + bytesize(part) }
headers['Content-Length'] = length.to_s
end

View file

@ -0,0 +1,23 @@
require 'rack/utils'
module Rack
# Sets the Content-Type header on responses which don't have one.
#
# Builder Usage:
# use Rack::ContentType, "text/plain"
#
# When no content type argument is provided, "text/html" is assumed.
class ContentType
def initialize(app, content_type = "text/html")
@app, @content_type = app, content_type
end
def call(env)
status, headers, body = @app.call(env)
headers = Utils::HeaderHash.new(headers)
headers['Content-Type'] ||= @content_type
[status, headers.to_hash, body]
end
end
end

View file

@ -36,12 +36,12 @@ module Rack
mtime = headers.key?("Last-Modified") ?
Time.httpdate(headers["Last-Modified"]) : Time.now
body = self.class.gzip(body, mtime)
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
size = Rack::Utils.bytesize(body)
headers = headers.merge("Content-Encoding" => "gzip", "Content-Length" => size.to_s)
[status, headers, [body]]
when "deflate"
body = self.class.deflate(body)
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
size = Rack::Utils.bytesize(body)
headers = headers.merge("Content-Encoding" => "deflate", "Content-Length" => size.to_s)
[status, headers, [body]]
when "identity"

View file

@ -70,7 +70,7 @@ table { width:100%%; }
return unless @path_info.include? ".."
body = "Forbidden\n"
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
size = Rack::Utils.bytesize(body)
return [403, {"Content-Type" => "text/plain","Content-Length" => size.to_s}, [body]]
end
@ -89,6 +89,8 @@ table { width:100%%; }
type = stat.directory? ? 'directory' : Mime.mime_type(ext)
size = stat.directory? ? '-' : filesize_format(size)
mtime = stat.mtime.httpdate
url << '/' if stat.directory?
basename << '/' if stat.directory?
@files << [ url, basename, size, type, mtime ]
end
@ -120,7 +122,7 @@ table { width:100%%; }
def entity_not_found
body = "Entity not found: #{@path_info}\n"
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
size = Rack::Utils.bytesize(body)
return [404, {"Content-Type" => "text/plain", "Content-Length" => size.to_s}, [body]]
end

View file

@ -60,7 +60,7 @@ module Rack
body = self
else
body = [F.read(@path)]
size = body.first.size
size = Utils.bytesize(body.first)
end
[200, {

View file

@ -1,3 +1,5 @@
require 'rack/content_length'
module Rack
module Handler
class CGI
@ -6,6 +8,8 @@ module Rack
end
def self.serve(app)
app = ContentLength.new(app)
env = ENV.to_hash
env.delete "HTTP_CONTENT_LENGTH"

View file

@ -1,5 +1,6 @@
require 'fcgi'
require 'socket'
require 'rack/content_length'
module Rack
module Handler
@ -29,6 +30,8 @@ module Rack
end
def self.serve(request, app)
app = Rack::ContentLength.new(app)
env = request.env
env.delete "HTTP_CONTENT_LENGTH"

View file

@ -1,5 +1,6 @@
require 'lsapi'
#require 'cgi'
require 'rack/content_length'
module Rack
module Handler
class LSWS
@ -9,11 +10,13 @@ module Rack
end
end
def self.serve(app)
app = Rack::ContentLength.new(app)
env = ENV.to_hash
env.delete "HTTP_CONTENT_LENGTH"
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
env.update({"rack.version" => [0,1],
"rack.input" => $stdin,
"rack.input" => StringIO.new($stdin.read.to_s),
"rack.errors" => $stderr,
"rack.multithread" => false,
"rack.multiprocess" => true,

View file

@ -1,5 +1,7 @@
require 'mongrel'
require 'stringio'
require 'rack/content_length'
require 'rack/chunked'
module Rack
module Handler
@ -33,7 +35,7 @@ module Rack
end
def initialize(app)
@app = app
@app = Rack::Chunked.new(Rack::ContentLength.new(app))
end
def process(request, response)

View file

@ -1,5 +1,7 @@
require 'scgi'
require 'stringio'
require 'rack/content_length'
require 'rack/chunked'
module Rack
module Handler
@ -14,7 +16,7 @@ module Rack
end
def initialize(settings = {})
@app = settings[:app]
@app = Rack::Chunked.new(Rack::ContentLength.new(settings[:app]))
@log = Object.new
def @log.info(*args); end
def @log.error(*args); end

View file

@ -1,9 +1,12 @@
require "thin"
require "rack/content_length"
require "rack/chunked"
module Rack
module Handler
class Thin
def self.run(app, options={})
app = Rack::Chunked.new(Rack::ContentLength.new(app))
server = ::Thin::Server.new(options[:Host] || '0.0.0.0',
options[:Port] || 8080,
app)

View file

@ -1,5 +1,6 @@
require 'webrick'
require 'stringio'
require 'rack/content_length'
module Rack
module Handler
@ -14,7 +15,7 @@ module Rack
def initialize(server, app)
super server
@app = app
@app = Rack::ContentLength.new(app)
end
def service(req, res)
@ -35,7 +36,12 @@ module Rack
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["QUERY_STRING"] ||= ""
env["REQUEST_PATH"] ||= "/"
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
if env["PATH_INFO"] == ""
env.delete "PATH_INFO"
else
path, n = req.request_uri.path, env["SCRIPT_NAME"].length
env["PATH_INFO"] = path[n, path.length-n]
end
status, headers, body = @app.call(env)
begin

View file

@ -88,7 +88,9 @@ module Rack
## within the application. This may be an
## empty string, if the request URL targets
## the application root and does not have a
## trailing slash.
## trailing slash. This information should be
## decoded by the server if it comes from a
## URL.
## <tt>QUERY_STRING</tt>:: The portion of the request URL that
## follows the <tt>?</tt>, if any. May be
@ -372,59 +374,43 @@ module Rack
## === The Content-Length
def check_content_length(status, headers, env)
chunked_response = false
headers.each { |key, value|
if key.downcase == 'transfer-encoding'
chunked_response = value.downcase != 'identity'
end
}
headers.each { |key, value|
if key.downcase == 'content-length'
## There must be a <tt>Content-Length</tt>, except when the
## +Status+ is 1xx, 204 or 304, in which case there must be none
## given.
## There must not be a <tt>Content-Length</tt> header when the
## +Status+ is 1xx, 204 or 304.
assert("Content-Length header found in #{status} response, not allowed") {
not Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i
}
assert('Content-Length header should not be used if body is chunked') {
not chunked_response
}
bytes = 0
string_body = true
@body.each { |part|
unless part.kind_of?(String)
string_body = false
break
end
if @body.respond_to?(:to_ary)
@body.each { |part|
unless part.kind_of?(String)
string_body = false
break
end
bytes += (part.respond_to?(:bytesize) ? part.bytesize : part.size)
}
if env["REQUEST_METHOD"] == "HEAD"
assert("Response body was given for HEAD request, but should be empty") {
bytes == 0
bytes += Rack::Utils.bytesize(part)
}
else
if string_body
assert("Content-Length header was #{value}, but should be #{bytes}") {
value == bytes.to_s
if env["REQUEST_METHOD"] == "HEAD"
assert("Response body was given for HEAD request, but should be empty") {
bytes == 0
}
else
if string_body
assert("Content-Length header was #{value}, but should be #{bytes}") {
value == bytes.to_s
}
end
end
end
return
end
}
if [ String, Array ].include?(@body.class) && !chunked_response
assert('No Content-Length header found') {
Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i
}
end
end
## === The Body

View file

@ -16,6 +16,8 @@ module Rack
# Your application's +call+ should end returning Response#finish.
class Response
attr_accessor :length
def initialize(body=[], status=200, header={}, &block)
@status = status
@header = Utils::HeaderHash.new({"Content-Type" => "text/html"}.

View file

@ -27,7 +27,7 @@ module Rack
message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
detail = env["rack.showstatus.detail"] || message
body = @template.result(binding)
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
size = Rack::Utils.bytesize(body)
[status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]]
else
[status, headers, body]

View file

@ -12,7 +12,11 @@ module Rack
# first, since they are most specific.
class URLMap
def initialize(map)
def initialize(map = {})
remap(map)
end
def remap(map)
@mapping = map.map { |location, app|
if location =~ %r{\Ahttps?://(.*?)(/.*)}
host, location = $1, $2

View file

@ -144,6 +144,19 @@ module Rack
end
module_function :select_best_encoding
# Return the bytesize of String; uses String#length under Ruby 1.8 and
# String#bytesize under 1.9.
if ''.respond_to?(:bytesize)
def bytesize(string)
string.bytesize
end
else
def bytesize(string)
string.size
end
end
module_function :bytesize
# Context allows the use of a compatible middleware at different points
# in a request handling stack. A compatible middleware must define
# #context which should take the arguments env and app. The first of which
@ -359,7 +372,7 @@ module Rack
data = body
end
Utils.normalize_params(params, name, data)
Utils.normalize_params(params, name, data) unless data.nil?
break if buf.empty? || content_length == -1
}