Skip to content

Commit

Permalink
Merge pull request #2 from mamantoha/small-imp
Browse files Browse the repository at this point in the history
small improvement
  • Loading branch information
mamantoha authored Nov 2, 2017
2 parents 3bd0a41 + 84b8216 commit b120ade
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/http/proxy/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ class HTTP::Proxy::Server < HTTP::Server
getter :host, :port

def initialize(@host = "127.0.0.1", @port = 8080)
handler = self.class.build_middleware
handler = build_middleware
@processor = RequestProcessor.new(handler)
end

def initialize(@host = "127.0.0.1", @port = 8080, &handler : Handler::Proc)
handler = self.class.build_middleware(handler)
handler = build_middleware(handler)
@processor = RequestProcessor.new(handler)
end

def initialize(@host = "127.0.0.1", @port = 8080, *, handlers : Array(HTTP::Handler), &handler : Handler::Proc)
handler = self.class.build_middleware(handlers, handler)
handler = build_middleware(handlers, handler)
@processor = RequestProcessor.new(handler)
end

def initialize(@host = "127.0.0.1", @port = 8080, *, handlers : Array(HTTP::Handler))
handler = self.class.build_middleware(handlers)
handler = build_middleware(handlers)
@processor = RequestProcessor.new(handler)
end

def initialize(@host = "127.0.0.1", @port = 8080, *, handler : HTTP::Handler | Handler::Proc)
handler = self.class.build_middleware(handler)
handler = build_middleware(handler)
@processor = RequestProcessor.new(handler)
end

def self.build_middleware(handler : Handler::Proc? = nil)
private def build_middleware(handler : Handler::Proc? = nil)
proxy_handler = Handler.new
proxy_handler.next = handler if handler
proxy_handler
end

def self.build_middleware(handlers, last_handler : Handler::Proc? = nil)
private def build_middleware(handlers, last_handler : Handler::Proc? = nil)
proxy_handler = build_middleware(last_handler)
return proxy_handler if handlers.empty?

Expand Down

0 comments on commit b120ade

Please sign in to comment.