[macruby-changes] [4269] ControlTower/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jun 22 23:07:05 PDT 2010
Revision: 4269
http://trac.macosforge.org/projects/ruby/changeset/4269
Author: joshua.ballanco at apple.com
Date: 2010-06-22 23:07:04 -0700 (Tue, 22 Jun 2010)
Log Message:
-----------
Bringing in a few ancillary changes from the gcd-ify branch
Modified Paths:
--------------
ControlTower/trunk/.gitignore
ControlTower/trunk/bin/control_tower
ControlTower/trunk/ext/CTParser/CTParser.m
ControlTower/trunk/lib/control_tower/rack_socket.rb
ControlTower/trunk/lib/control_tower/server.rb
Added Paths:
-----------
ControlTower/trunk/HACKING.rdoc
ControlTower/trunk/README.rdoc
ControlTower/trunk/TODO
ControlTower/trunk/sample/
ControlTower/trunk/sample/file_upload.ru
ControlTower/trunk/sample/simple_hello.ru
Removed Paths:
-------------
ControlTower/trunk/README
Modified: ControlTower/trunk/.gitignore
===================================================================
--- ControlTower/trunk/.gitignore 2010-06-23 06:04:01 UTC (rev 4268)
+++ ControlTower/trunk/.gitignore 2010-06-23 06:07:04 UTC (rev 4269)
@@ -1,3 +1,3 @@
*.bundle
*.o
-pkg/*
+pkg
Added: ControlTower/trunk/HACKING.rdoc
===================================================================
--- ControlTower/trunk/HACKING.rdoc (rev 0)
+++ ControlTower/trunk/HACKING.rdoc 2010-06-23 06:07:04 UTC (rev 4269)
@@ -0,0 +1,74 @@
+== Hacking Control Tower
+
+Control Tower is still in very early development. It is being developed as part
+of the MacRuby project, so be sure to familiarize yourself with MacRuby's
+HACKING.rdoc, as all guidelines there apply here as well. If you have any ideas
+or suggestions for improvements, please communicate them with the MacRuby
+developer's list at <macruby-devel at lists.macosforge.org>. You can also find more
+information at the MacRuby website (http://www.macruby.org/).
+
+
+== CAUTION! AVERTISSEMENT! VOORZICHTIG! 注意!
+
+DO NOT EDIT http11_parser.c! THIS FILE CONTAINS MACHINE GENERATED CODE.
+N'EDITEZ PAS http11_parser.c! Ce fichier a été généré automatiquement.
+WIJZIG http11_parser.c NIET! Dit bestand bevat MACHINE gegenereerde code.
+http11_parser.cを編集しないでください!このファイルが機械生成されいます。
+
+If you really must, you can recreate http11_parser.c from http11_parser.rl using
+Ragel (not included). It would also be acceptable to replace the parser all at
+once, but editing it is not likely to ever be a good idea.
+
+
+== Sample Code
+
+There are two samples that you can run to explore ControlTower's behavior on GET
+and POST requests located in the 'sample' directory. To use these samples, first
+build and install the Control Tower gem:
+
+> rake gem
+> sudo macgem install pkg/control_tower-0.1-universal-darwin-10.gem
+
+Then, to try a GET request, start the 'simple_hello.ru' rack-up config like so:
+
+> control_tower -R sample/simple_hello.ru
+
+and test it with a utility such as curl like so:
+
+> curl http://localhost:8080/
+
+This should reply with a very traditional string and a read-out of the rack
+environment generated by your request. To try a POST request, start the
+'file_upload.ru' config as above, then use curl (or similar tool) to send a post
+with some file content like so:
+
+> curl -F "file=@README.rdoc" http://localhost:8080/
+
+This command tells curl to send the file as a form parameter, and the reply
+should contain the content of the rack 'params' variable constructed from this
+parameter. In particular, when the parameter is named 'file', the
+'file_upload.ru' sample will return the contents of the file.
+
+
+== Debugging
+
+=== Environment variables
+
+Currently, there is only one environment variable specifically for debugging
+Control Tower:
+
+* CT_DEBUG: This will turn on debug logging until we get a better logger.
+
+
+== Known Issues
+
+* Error compiling Regular Expression in Rack::Request
+ Workaround: Modify line 150 in rack/request.rb like so
+- form_vars.sub!(/\0\z/, '')
++ form_vars.slice!(-1) if form_vars[-1] == "\0"
+
+* Problem with Sinatra > 1.0 using Rack.release
+ Workaround: Modify line 39 in sinatra/base.rb like so
+- if Rack.release < '1.1'
++ if Rack.version < '1.1'
+
Deleted: ControlTower/trunk/README
===================================================================
--- ControlTower/trunk/README 2010-06-23 06:04:01 UTC (rev 4268)
+++ ControlTower/trunk/README 2010-06-23 06:07:04 UTC (rev 4269)
@@ -1,9 +0,0 @@
-Control Tower
-
-Copyright (c) 2009-2010, Apple Inc
-Author: Joshua Ballanco
-
-SYNOPSIS
-Control Tower is a Web application server for Rack-based Ruby applications. It
-is (or will be) composed of three major components: a networking layer, an HTTP
-parser, and a Rack interface.
Added: ControlTower/trunk/README.rdoc
===================================================================
--- ControlTower/trunk/README.rdoc (rev 0)
+++ ControlTower/trunk/README.rdoc 2010-06-23 06:07:04 UTC (rev 4269)
@@ -0,0 +1,31 @@
+== Control Tower
+Control Tower is a web application server for Rack-based MacRuby applications based on Apple's Grand Central Dispatch libraries.
+
+It is composed of three major components: A Grand Central Dispatch based networking layer, the Mongrel HTTP parser, and Rack web
+application interface. It is currently very much a work in progress!
+
+=== Installation
+From the root directory of the project, run:
+
+ $ rake package
+ $ sudo macgem install pkg/control_tower-0.1-universal-darwin-10.gem
+
+=== Usage
+There are currently only 4 supported command line options:
+
+* -R <rackup_config.ru> : Where you specify the Rackup config file to run
+* -h <hostname> : Hostname for the server (Control Tower will only respond to requests to this host)
+* -p <port> : Port # for the server
+* -c : Use this to enable serving requests to a GCD concurrent queue
+
+=== License
+Control Tower is covered by the Ruby license. See COPYING for more details.
+
+=== Credits
+Control Tower's parser was stolen Thin which stole it from Mongrel (http://mongrel.rubyforge.org) originially written by Zed Shaw.
+Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw <zedshaw at zedshaw dot com> You can redistribute it and/or
+modify it under the terms of the GPL.
+
+Thin is copyright Marc-Andre Cournoyer <macournoyer at gmail.com>
+
+Control Tower is copyright (c) 2009-2010, Apple Inc
Added: ControlTower/trunk/TODO
===================================================================
--- ControlTower/trunk/TODO (rev 0)
+++ ControlTower/trunk/TODO 2010-06-23 06:07:04 UTC (rev 4269)
@@ -0,0 +1,20 @@
+For 0.1:
+
+[ ] Logging!
+ [ ] An ASL-based Logger class
+ [ ] Request logging (e.g. appache_access.log)
+ [ ] Error logging (e.g. appache_error.log)
+ [ ] Debug logging
+[ ] Testing!
+ [ ] Parser test cases
+ [ ] GET test cases
+ [ ] POST test cases
+ [ ] Concurrency testing
+[ ] Handle broken request pipes
+[ ] Don't reset peer connections
+[ ] Protect against malformed Content-Length in headers
+
+For future:
+
+[ ] Improve body loading
+[ ] Fully-async file upload
Modified: ControlTower/trunk/bin/control_tower
===================================================================
--- ControlTower/trunk/bin/control_tower 2010-06-23 06:04:01 UTC (rev 4268)
+++ ControlTower/trunk/bin/control_tower 2010-06-23 06:07:04 UTC (rev 4269)
@@ -9,7 +9,8 @@
@options = {
:rackup => './config.ru',
:port => '8080',
- :host => 'localhost'
+ :host => 'localhost',
+ :concurrent => false
}
OptionParser.new do |opts|
@@ -25,7 +26,7 @@
@options[:host] = host
end
- opts.on("-c", "--[no]-concurrency", "Handle requests concurrently") do |concurrent|
+ opts.on("-c", "--[no-]concurrency", "Handle requests concurrently") do |concurrent|
@options[:concurrent] = concurrent
end
end.parse!
@@ -35,16 +36,11 @@
exit 1
end
-unless File.exist? File.expand_path(@options[:rackup])
- puts "We only know how to deal with Rack-up configs for now"
- exit 1
-end
-
# Under construction...everything is development!
ENV['RACK_ENV'] = 'development'
rackup_config = File.read(File.expand_path(@options[:rackup]))
-app = eval("Rack::Builder.new { #{rackup_config} }.to_app")
+app = eval("Rack::Builder.new { #{rackup_config} }").to_app
# Let's get to business!
server = ControlTower::Server.new(app, @options)
Modified: ControlTower/trunk/ext/CTParser/CTParser.m
===================================================================
--- ControlTower/trunk/ext/CTParser/CTParser.m 2010-06-23 06:04:01 UTC (rev 4268)
+++ ControlTower/trunk/ext/CTParser/CTParser.m 2010-06-23 06:07:04 UTC (rev 4269)
@@ -81,7 +81,8 @@
if (colon_pos.location != NSNotFound) {
serverName = [hostString substringToIndex:colon_pos.location];
serverPort = [hostString substringFromIndex:(colon_pos.location + 1)];
- } else {
+ }
+ else {
serverName = [NSString stringWithString:hostString];
serverPort = @"80";
}
@@ -104,7 +105,8 @@
NSMutableString *body = [environment objectForKey:@"rack.input"];
if (body != nil) {
[body appendString:[[NSString alloc] initWithBytes:at length:length encoding:NSASCIIStringEncoding]];
- } else {
+ }
+ else {
NSLog(@"Hmm...you seem to have body data but no where to put it. That's probably an error.");
}
Modified: ControlTower/trunk/lib/control_tower/rack_socket.rb
===================================================================
--- ControlTower/trunk/lib/control_tower/rack_socket.rb 2010-06-23 06:04:01 UTC (rev 4268)
+++ ControlTower/trunk/lib/control_tower/rack_socket.rb 2010-06-23 06:07:04 UTC (rev 4269)
@@ -14,7 +14,6 @@
@server = server
@socket = TCPServer.new(host, port)
@status = :closed # Start closed and give the server time to start
- prepare_environment
#if concurrent
# @env['rack.multithread'] = true
Modified: ControlTower/trunk/lib/control_tower/server.rb
===================================================================
--- ControlTower/trunk/lib/control_tower/server.rb 2010-06-23 06:04:01 UTC (rev 4268)
+++ ControlTower/trunk/lib/control_tower/server.rb 2010-06-23 06:07:04 UTC (rev 4269)
@@ -20,6 +20,7 @@
end
def handle_request(env)
+ env
wrap_output(*@app.call(env))
end
Added: ControlTower/trunk/sample/file_upload.ru
===================================================================
--- ControlTower/trunk/sample/file_upload.ru (rev 0)
+++ ControlTower/trunk/sample/file_upload.ru 2010-06-23 06:07:04 UTC (rev 4269)
@@ -0,0 +1,17 @@
+require 'rack'
+
+class Uploader
+ def call(env)
+ params = Rack::Request.new(env).params
+ response = params.map do |k,v|
+ if k == 'file' && v[:tempfile]
+ "#{k} => File Contents: #{v[:tempfile].read}"
+ else
+ "#{k} => #{v.inspect}"
+ end
+ end.join("\n") + "\n"
+ [200, { 'Content-Type' => 'text/plain' }, response]
+ end
+end
+
+run Uploader.new
Added: ControlTower/trunk/sample/simple_hello.ru
===================================================================
--- ControlTower/trunk/sample/simple_hello.ru (rev 0)
+++ ControlTower/trunk/sample/simple_hello.ru 2010-06-23 06:07:04 UTC (rev 4269)
@@ -0,0 +1,7 @@
+class Hello
+ def call(env)
+ [200, { 'Content-Type' => 'text/plain' }, "Hello, world! Your environment is #{env}"]
+ end
+end
+
+run Hello.new
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100622/94bce18c/attachment-0001.html>
More information about the macruby-changes
mailing list