9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/basic_auth_mark/middleware.rb', line 9
def call(env)
status, , response = @app.call(env)
return [status, , response] unless ['Content-Type'].to_s =~ %r{\btext/html\b}i
return [status, , response] if status >= 300 && status < 400
request = Rack::Auth::Basic::Request.new(env)
if request.provided? && request.basic?
new_body = ''
response.each do |b|
begin
new_body << insert_basic_auth_marks(b)
rescue => exception
$stderr.write %Q|Failed to insert basic auth marks: #{exception.message}\n #{exception.backtrace.join(" \n")}|
end
end
response.close if response.respond_to?(:close)
['Content-Length'] &&= new_body.bytesize.to_s
response = [new_body]
end
[status, , response]
end
|