Skip to content
This repository has been archived by the owner on Nov 16, 2017. It is now read-only.

Commit

Permalink
Remove unused StringIO, expect options hash with application instead …
Browse files Browse the repository at this point in the history
…of application itself
  • Loading branch information
marekjelen committed Mar 31, 2012
1 parent 4788395 commit e64aba4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions 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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit e64aba4

Please sign in to comment.