lib/baurets/optionsful/server.rb in optionsful-0.3.2 vs lib/baurets/optionsful/server.rb in optionsful-0.4.0

- old
+ new

@@ -1,34 +1,44 @@ module Baurets module Optionsful class Server + ## + # Wakes up! + # def initialize(app) @app = app @config = Config.new end + ## + # Handle HTTP OPTIONS requests. + # def call(env) unless env["REQUEST_METHOD"] == "OPTIONS" @app.call(env) else @env = env build_response end end private + + def extract_options_information + allows = ::Baurets::Optionsful::Introspections.do_the_matches(@env["PATH_INFO"]) + end def build_response allows = extract_options_information headers = {} status = 500 body = "" unless allows.empty? headers.merge!({"Allow" => allows}) status = 204 - if @config.link + if @config.link == true headers.merge!({"Link" => build_link_header}) end else status = 404 body = "Not found" @@ -49,16 +59,11 @@ link += @config.base_path unless @config.base_path == "/" end if @config.propagate == true link += @env["PATH_INFO"] end - link += ">; type=text/html; rel=help\"" link - end - - def extract_options_information - allows = ::Baurets::Optionsful::Introspections.do_the_matches(@env["PATH_INFO"]) end end end end