GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: the 4k pocket full-of-gags web microframework
Homepage: http://code.whytheluckystiff.net/camping/
Clone URL: git://github.com/why/camping.git
Fixing bin/camping (and friends) to use the Rack adapter
judofyr (author)
Tue May 20 13:00:27 -0700 2008
commit  1dcec1197078720661ff932d4496b1a558372714
tree    23580c4b5776a0ae7a87049fb236bba80f0d13af
parent  97320819718deb6384d958e6fb9bf52c98d98bfa
...
1
2
 
3
4
5
...
86
87
88
89
90
91
92
...
94
95
96
97
98
99
 
100
...
1
2
3
4
5
6
...
87
88
89
 
90
91
92
...
94
95
96
 
 
 
97
98
0
@@ -1,5 +1,6 @@
0
 #!/usr/bin/env ruby
0
 
0
+trap("INT") { exit }
0
 require 'optparse'
0
 require 'ostruct'
0
 require 'stringio'
0
@@ -86,7 +87,6 @@ paths = ARGV.dup
0
 if conf.server.nil? || conf.server == "mongrel"
0
     begin
0
         require 'mongrel'
0
- require 'mongrel/camping'
0
         conf.server = "mongrel"
0
     rescue LoadError
0
         puts "!! could not load mongrel. Falling back to webrick."
0
@@ -94,7 +94,5 @@ if conf.server.nil? || conf.server == "mongrel"
0
     end
0
 end
0
 
0
-require "camping/server/#{conf.server}"
0
-
0
-server = Camping::Server.const_get(conf.server.capitalize).new(conf, paths)
0
+server = Camping::Server::Base.new(conf, paths)
0
 server.start
...
112
113
114
115
 
116
117
118
 
119
120
121
...
112
113
114
 
115
116
117
 
118
119
120
121
0
@@ -112,10 +112,10 @@ class Reloader
0
 
0
     # Conditionally reloads (using reload_app.) Then passes the request through
0
     # to the wrapped Camping app.
0
- def run(*a)
0
+ def call(*a)
0
         reload_app
0
         if @klass
0
- @klass.run(*a)
0
+ @klass.call(*a)
0
         else
0
             Camping.run(*a)
0
         end
...
 
 
1
2
3
...
91
92
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
95
96
97
98
99
100
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
...
1
2
3
4
5
...
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
0
@@ -1,3 +1,5 @@
0
+require 'irb'
0
+require 'rack'
0
 require 'camping/reloader'
0
 
0
 module Camping::Server
0
@@ -91,11 +93,65 @@ class Base < Hash
0
       self.values
0
   end
0
   
0
+ def start
0
+ handler, conf = case @conf.server
0
+ when "console"
0
+ ARGV.clear
0
+ IRB.start
0
+ exit
0
+ when "mongrel"
0
+ puts "** Starting Mongrel on #{@conf.host}:#{@conf.port}"
0
+ [Rack::Handler::Mongrel, {:Port => @conf.port, :Host => @conf.host}]
0
+ when "webrick"
0
+ [Rack::Handler::WEBrick, {:Port => @conf.port, :BindAddress => @conf.host}]
0
+ end
0
+
0
+ rapp = if apps.length > 1
0
+ hash = {
0
+ "/" => proc {|env|[200,{'Content-Type'=>'text/html'},index_page]}
0
+ }
0
+ apps.each do |app|
0
+ hash["/#{app.mount}"] = app
0
+ hash["/code/#{app.mount}"] = proc do |env|
0
+ [200,{'Content-Type'=>'text/plain'},app.view_source]
0
+ end
0
+ end
0
+ Rack::URLMap.new(hash)
0
+ else
0
+ apps.first
0
+ end
0
+ rapp = XSendfile.new(rapp)
0
+ rapp = Rack::ShowExceptions.new(rapp)
0
+ handler.run(rapp, conf)
0
+ end
0
+
0
   private
0
   
0
   def insert_app(script)
0
     self[script] = Camping::Reloader.new(script)
0
   end
0
 end
0
-end
0
 
0
+# A Rack middleware for reading X-Sendfile. Should only be used in
0
+# development.
0
+class XSendfile
0
+
0
+ HEADERS = [
0
+ "X-Sendfile",
0
+ "X-Accel-Redirect",
0
+ "X-LIGHTTPD-send-file"
0
+ ]
0
+
0
+ def initialize(app)
0
+ @app = app
0
+ end
0
+
0
+ def call(env)
0
+ status, headers, body = @app.call(env)
0
+ if path = headers.values_at(*HEADERS).compact.first
0
+ body = File.read(path)
0
+ end
0
+ [status, headers, body]
0
+ end
0
+end
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.