File: handler.rb

package info (click to toggle)
ruby-rack-oauth2 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 564 kB
  • sloc: ruby: 4,038; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 814 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Rack
  module OAuth2
    module Server
      module Abstract
        class Handler
          attr_accessor :authenticator, :request, :response

          def initialize(&authenticator)
            @authenticator = authenticator
          end

          def call(env)
            # NOTE:
            #  Rack middleware is initialized only on the first request of the process.
            #  So any instance variables are acts like class variables, and modifying them in call() isn't thread-safe.
            #  ref.) http://stackoverflow.com/questions/23028226/rack-middleware-and-thread-safety
            dup._call(env)
          end

          def _call(env)
            @authenticator.call(@request, @response) if @authenticator
            @response
          end
        end
      end
    end
  end
end