From e64aba4e8fabaaa100e88d8fa286a61f4becd5d2 Mon Sep 17 00:00:00 2001 From: Marek Jelen Date: Sat, 31 Mar 2012 12:17:36 +0200 Subject: [PATCH] Remove unused StringIO, expect options hash with application instead of application itself --- lib/thick/server_handler.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/thick/server_handler.rb b/lib/thick/server_handler.rb index 463e2a2..4242513 100644 --- a/lib/thick/server_handler.rb +++ b/lib/thick/server_handler.rb @@ -1,12 +1,10 @@ -require 'stringio' - module Thick class ServerHandler < Thick::Java::SimpleChannelUpstreamHandler - def initialize(application) + def initialize(options) super() - @application = application + @options = options end def channelConnected(context, event) @@ -32,7 +30,7 @@ def serve_file(context, file, from = 0, to = nil) def on_request(context, request) # Serve file if exists in public directory - file = File.join('public', request.uri) + file = File.join(@options[:directory], 'public', request.uri) return serve_file(context, file).addListener(Thick::Java::ChannelFutureListener::CLOSE) if !request.uri.index('..') && File.exists?(file) && !File.directory?(file) query_string = request.uri.split('?', 2) @@ -53,7 +51,8 @@ def on_request(context, request) 'SERVER_NAME' => 'localhost', # ToDo: Be more precise! 'SERVER_PORT' => '8080', # ToDo: Be more precise! # Thick specific - 'thick.async' => AsyncResponse.new(context) + 'thick.async' => AsyncResponse.new(context), + 'thick.options' => @options } # Get content length if available @@ -83,7 +82,7 @@ def on_chunk(context, chunk) end def handle_request(context) - response = @application.call(@env) + response = @options[:application].call(@env) # Let the application make the response as it wants if @env['thick.async'].custom?