Permalink
Browse files

Fix trailing whitespace. Sigh.

darcs-hash:20070516145358-4fc50-4b716d93f0cc24d1e988443228312c6bcdfc1e7b.gz
  • Loading branch information...
1 parent e256ec6 commit 230d62c722ee24202a29b017c59d3229bc6e1e89 @chneukirchen committed May 16, 2007
View
@@ -2,7 +2,7 @@ module Rack
# Rack::CommonLogger forwards every request to an +app+ given, and
# logs a line in the Apache common log format to the +logger+, or
# rack.errors by default.
-
+
class CommonLogger
def initialize(app, logger=nil)
@app = app
View
@@ -4,7 +4,7 @@ module Rack
#
# Handlers can detect if bodies are a Rack::File, and use mechanisms
# like sendfile on the +path+.
-
+
class File
attr_accessor :root
attr_accessor :path
View
@@ -4,7 +4,7 @@ class CGI
def self.run(app, options=nil)
serve app
end
-
+
def self.serve(app)
env = ENV.to_hash
env.delete "HTTP_CONTENT_LENGTH"
@@ -14,18 +14,18 @@ def self.serve(app)
env.update({"rack.version" => [0,1],
"rack.input" => STDIN,
"rack.errors" => STDERR,
-
+
"rack.multithread" => false,
"rack.multiprocess" => true,
"rack.run_once" => true,
-
+
"rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
})
-
+
env["QUERY_STRING"] ||= ""
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["REQUEST_PATH"] ||= "/"
-
+
status, headers, body = app.call(env)
begin
send_headers status, headers
@@ -34,7 +34,7 @@ def self.serve(app)
body.close if body.respond_to? :close
end
end
-
+
def self.send_headers(status, headers)
STDOUT.print "Status: #{status}\r\n"
headers.each { |k, vs|
@@ -45,7 +45,7 @@ def self.send_headers(status, headers)
STDOUT.print "\r\n"
STDOUT.flush
end
-
+
def self.send_body(body)
body.each { |part|
STDOUT.print part
@@ -11,31 +11,31 @@ def self.run(app, options={})
yield server if block_given?
server.run.join
end
-
+
def initialize(app)
@app = app
end
-
+
def process(request, response)
env = {}.replace(request.params)
env.delete "HTTP_CONTENT_TYPE"
env.delete "HTTP_CONTENT_LENGTH"
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
-
+
env.update({"rack.version" => [0,1],
"rack.input" => request.body || StringIO.new(""),
"rack.errors" => STDERR,
-
+
"rack.multithread" => true,
"rack.multiprocess" => false, # ???
"rack.run_once" => false,
-
+
"rack.url_scheme" => "http",
})
env["QUERY_STRING"] ||= ""
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
-
+
status, headers, body = @app.call(env)
begin
@@ -11,27 +11,27 @@ def self.run(app, options={})
yield server if block_given?
server.start
end
-
+
def initialize(server, app)
super server
@app = app
end
-
+
def service(req, res)
env = req.meta_vars
env.delete_if { |k, v| v.nil? }
-
+
env.update({"rack.version" => [0,1],
"rack.input" => StringIO.new(req.body.to_s),
"rack.errors" => STDERR,
-
+
"rack.multithread" => true,
"rack.multiprocess" => false,
"rack.run_once" => false,
-
+
"rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
})
-
+
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["QUERY_STRING"] ||= ""
env["REQUEST_PATH"] ||= "/"
View
@@ -1,7 +1,7 @@
module Rack
# Rack::Lint validates your application and the requests and
# responses according to the Rack spec.
-
+
class Lint
def initialize(app)
@app = app
@@ -47,7 +47,7 @@ def call(env=nil)
check_content_type status, headers
[status, headers, self]
end
-
+
## == The Environment
def check_env(env)
## The environment must be an true instance of Hash (no
@@ -210,7 +210,7 @@ class InputWrapper
def initialize(input)
@input = input
end
-
+
## * +gets+ must be called without arguments and return a string,
## or +nil+ on EOF.
def gets(*args)
View
@@ -21,14 +21,14 @@ class Lobster
lobster = LobsterString
href = "?flip"
end
-
+
[200, {"Content-Type" => "text/html"},
["<title>Lobstericious!</title>",
"<pre>", lobster, "</pre>",
"<a href='#{href}'>flip!</a>"]
]
}
-
+
def call(env)
req = Request.new(env)
if req.GET["flip"] == "left"
@@ -42,7 +42,7 @@ def call(env)
lobster = LobsterString
href = "?flip=left"
end
-
+
Response.new.finish do |res|
res.write "<title>Lobstericious!</title>"
res.write "<pre>"
View
@@ -17,7 +17,7 @@ module Rack
# <tt>:input</tt>:: A String or IO-like to be used as rack.input.
# <tt>:fatal</tt>:: Raise a FatalWarning if the app writes to rack.errors.
# <tt>:lint</tt>:: If true, wrap the application in a Rack::Lint.
-
+
class MockRequest
class FatalWarning < RuntimeError
end
View
@@ -28,7 +28,7 @@ def initialize(url, env={})
# include data from other applications (by using
# <tt>rack['rack.recursive.include'][...]</tt> or raise a
# ForwardRequest to redirect internally.
-
+
class Recursive
def initialize(app)
@app = app
View
@@ -6,7 +6,7 @@ module Rack
# rack.errors.
#
# It is recommended you use ShowExceptions to catch SyntaxErrors etc.
-
+
class Reloader
def initialize(app, secs=10)
@app = app
View
@@ -8,11 +8,11 @@ module Rack
# req = Rack::Request.new(env)
# req.post?
# req.params["data"]
-
+
class Request
# The environment of the request.
attr_reader :env
-
+
def initialize(env)
@env = env
end
@@ -59,7 +59,7 @@ def POST
else
@env["rack.request.form_input"] = @env["rack.input"]
unless @env["rack.request.form_hash"] =
- Utils::Multipart.parse_multipart(env)
+ Utils::Multipart.parse_multipart(env)
@env["rack.request.form_vars"] = @env["rack.input"].read
@env["rack.request.form_hash"] = Utils.parse_query(@env["rack.request.form_vars"])
end
View
@@ -120,36 +120,36 @@ def empty?
module Helpers
def invalid?; @status < 100 || @status >= 600; end
-
+
def informational?; @status >= 100 && @status < 200; end
def successful?; @status >= 200 && @status < 300; end
def redirection?; @status >= 300 && @status < 400; end
def client_error?; @status >= 400 && @status < 500; end
def server_error?; @status >= 500 && @status < 600; end
-
+
def ok?; @status == 200; end
def forbidden?; @status == 403; end
def not_found?; @status == 404; end
-
+
def redirect?; [301, 302, 303, 307].include? @status; end
def empty?; [201, 204, 304].include? @status; end
-
+
# Headers
attr_reader :headers, :original_headers
-
+
def include?(header)
!!headers[header]
end
-
+
def content_type
headers["Content-Type"]
end
-
+
def content_length
cl = headers["Content-Length"]
cl ? cl.to_i : cl
end
-
+
def location
headers["Location"]
end
View
@@ -2,10 +2,10 @@
module Rack
- module Session
+ module Session
# Rack::Session::Cookie provides simple cookie based session management.
- # The session is a Ruby Hash stored as base64 encoded marshalled data
+ # The session is a Ruby Hash stored as base64 encoded marshalled data
# set to :key (default: rack.session).
#
# Example:
@@ -22,54 +22,52 @@ class Cookie
def initialize(app, options={})
@app = app
@key = options[:key] || "rack.session"
- @default_options = {:domain => nil,
- :path => "/",
+ @default_options = {:domain => nil,
+ :path => "/",
:expire_after => nil}.merge(options)
- end
-
- def call(env)
- load_session(env)
- status, headers, body = @app.call(env)
- commit_session(env, status, headers, body)
- end
+ end
- private
+ def call(env)
+ load_session(env)
+ status, headers, body = @app.call(env)
+ commit_session(env, status, headers, body)
+ end
- def load_session(env)
- request = Rack::Request.new(env)
- session_data = request.cookies[@key]
+ private
- begin
- session_data = Base64.decode64(session_data)
- session_data = Marshal.load(session_data)
- env["rack.session"] = session_data
- rescue
- env["rack.session"] = Hash.new
- end
+ def load_session(env)
+ request = Rack::Request.new(env)
+ session_data = request.cookies[@key]
- env["rack.session.options"] = @default_options.dup
+ begin
+ session_data = Base64.decode64(session_data)
+ session_data = Marshal.load(session_data)
+ env["rack.session"] = session_data
+ rescue
+ env["rack.session"] = Hash.new
end
- def commit_session(env, status, headers, body)
- session_data = Marshal.dump(env["rack.session"])
- session_data = Base64.encode64(session_data)
+ env["rack.session.options"] = @default_options.dup
+ end
- if session_data.size > (4096 - @key.size)
- env["rack.errors"].puts("Warning! Rack::Session::Cookie data size exceeds 4K. Content dropped.")
- [status, headers, body]
- else
- options = env["rack.session.options"]
- cookie = Hash.new
- cookie[:value] = session_data
- cookie[:expires] = Time.now + options[:expire_after] unless options[:expire_after].nil?
- response = Rack::Response.new(body, status, headers)
- response.set_cookie(@key, cookie.merge(options))
- response.to_a
- end
- end
+ def commit_session(env, status, headers, body)
+ session_data = Marshal.dump(env["rack.session"])
+ session_data = Base64.encode64(session_data)
+ if session_data.size > (4096 - @key.size)
+ env["rack.errors"].puts("Warning! Rack::Session::Cookie data size exceeds 4K. Content dropped.")
+ [status, headers, body]
+ else
+ options = env["rack.session.options"]
+ cookie = Hash.new
+ cookie[:value] = session_data
+ cookie[:expires] = Time.now + options[:expire_after] unless options[:expire_after].nil?
+ response = Rack::Response.new(body, status, headers)
+ response.set_cookie(@key, cookie.merge(options))
+ response.to_a
+ end
end
- end
-
+ end
end
+end
Oops, something went wrong.

0 comments on commit 230d62c

Please sign in to comment.