rewrite work and log file cleanup
This commit is contained in:
parent
9e2010266c
commit
f6397e9034
@ -172,6 +172,6 @@ module Apache
|
||||
|
||||
end
|
||||
|
||||
block_methods :virtual_host, :files_match, :location
|
||||
block_methods :virtual_host, :files_match, :location, :files
|
||||
end
|
||||
end
|
||||
|
@ -1,23 +1,15 @@
|
||||
module Apache
|
||||
module Logging
|
||||
def error_log(*opts)
|
||||
handle_log 'ErrorLog', opts.first, opts.first, opts[1..-1]
|
||||
end
|
||||
[ :custom, :error, :script, :rewrite ].each do |type|
|
||||
class_eval <<-EOT
|
||||
def #{type}_log(*opts)
|
||||
handle_log '#{type.to_s.capitalize}Log', opts.first, opts.first, opts[1..-1]
|
||||
end
|
||||
|
||||
def custom_log(*opts)
|
||||
handle_log 'CustomLog', opts.first, opts.first, opts[1..-1]
|
||||
end
|
||||
|
||||
def rotate_custom_log(*opts)
|
||||
handle_log 'CustomLog', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
||||
end
|
||||
|
||||
def rotate_error_log(*opts)
|
||||
handle_log 'ErrorLog', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
||||
end
|
||||
|
||||
def rotate_script_log(*opts)
|
||||
handle_log 'ScriptLog', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
||||
def rotate_#{type}_log(*opts)
|
||||
handle_log '#{type.to_s.capitalize}Log', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
||||
end
|
||||
EOT
|
||||
end
|
||||
|
||||
def combined_log_format(name = 'combined')
|
||||
|
@ -46,5 +46,12 @@ module Apache
|
||||
end
|
||||
|
||||
alias :script_alias! :script_alias
|
||||
|
||||
def add_type!(mime, extension, options = {})
|
||||
self << "AddType #{mime} #{extension}"
|
||||
options.each do |type, value|
|
||||
self << "Add#{type.to_s.capitalize} #{value} #{extension}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -31,14 +31,27 @@ module Apache
|
||||
|
||||
self.instance_eval(&block)
|
||||
|
||||
@rewrites
|
||||
@rewrites.collect(&:to_a).flatten
|
||||
end
|
||||
|
||||
def commit!
|
||||
@rewrites << @rewrite
|
||||
@rewrite = nil
|
||||
end
|
||||
|
||||
def ensure_rewrite!
|
||||
@rewrite = RewriteRule.new if !@rewrite
|
||||
end
|
||||
|
||||
def rewrite(*opts)
|
||||
@rewrite = RewriteRule.new
|
||||
ensure_rewrite!
|
||||
@rewrite.rule(*opts)
|
||||
commit!
|
||||
end
|
||||
|
||||
@rewrites << @rewrite
|
||||
def cond(*opts)
|
||||
ensure_rewrite!
|
||||
@rewrite.cond(*opts)
|
||||
end
|
||||
|
||||
def r301(*opts)
|
||||
@ -63,6 +76,8 @@ module Apache
|
||||
end
|
||||
|
||||
class MatchableThing
|
||||
include Apache::Quoteize
|
||||
|
||||
def tag; raise 'Override this method'; end
|
||||
|
||||
def initialize
|
||||
@ -75,7 +90,14 @@ module Apache
|
||||
def rule(from, to, *opts)
|
||||
@from = from
|
||||
@to = to
|
||||
@options = opts
|
||||
@options = opts.first
|
||||
end
|
||||
|
||||
def cond(from, to, *opts)
|
||||
rewrite_cond = RewriteCondition.new
|
||||
rewrite_cond.cond(from, to, *opts)
|
||||
|
||||
@conditions << rewrite_cond
|
||||
end
|
||||
|
||||
def test(from, opts)
|
||||
@ -86,18 +108,29 @@ module Apache
|
||||
from
|
||||
end
|
||||
|
||||
def to_s
|
||||
output = []
|
||||
|
||||
@conditions.each do |condition|
|
||||
def to_a
|
||||
output = @conditions.collect(&:to_s)
|
||||
|
||||
options = @options.collect do |key, value|
|
||||
case key
|
||||
when :last
|
||||
'L'
|
||||
when :preserve_query_string
|
||||
'QSA'
|
||||
end
|
||||
end
|
||||
|
||||
output << "#{tag} #{[@from.source, @to, @options].flatten * " "}"
|
||||
if !options.empty?
|
||||
options = "[#{options * ','}]"
|
||||
else
|
||||
options = nil
|
||||
end
|
||||
|
||||
output * "\n"
|
||||
output << "#{tag} #{[quoteize(@from.source), quoteize(@to), options].compact.flatten * " "}"
|
||||
|
||||
output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class RewriteRule < MatchableThing
|
||||
def tag; 'RewriteRule'; end
|
||||
@ -106,4 +139,13 @@ end
|
||||
class RedirectMatchPermanent < MatchableThing
|
||||
def tag; 'RedirectMatch permanent'; end
|
||||
end
|
||||
|
||||
class RewriteCondition < MatchableThing
|
||||
def tag; 'RewriteCond'; end
|
||||
alias :cond :rule
|
||||
|
||||
def to_s
|
||||
"#{tag} #{[quoteize(@from), quoteize(@to), @options].flatten * " "}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user