lib/httpimagestore/configuration/handler.rb in httpimagestore-1.1.0 vs lib/httpimagestore/configuration/handler.rb in httpimagestore-1.2.0
- old
+ new
@@ -40,11 +40,11 @@
@locals[:path] = path
@locals.merge! matches
@locals[:query_string_options] = query_string.sort.map{|kv| kv.join(':')}.join(',')
log.debug "processing request with body length: #{body.bytesize} bytes and locals: #{@locals} "
- @locals[:body] = body
+ @locals[:_body] = body
@images = Images.new(memory_limit)
@memory_limit = memory_limit
@output_callback = nil
end
@@ -79,12 +79,12 @@
include ImageMetaData
end
class InputSource
def realize(request_state)
- request_state.locals[:body].empty? and raise ZeroBodyLengthError
- request_state.images['input'] = Image.new(request_state.locals[:body])
+ request_state.locals[:_body].empty? and raise ZeroBodyLengthError
+ request_state.images['input'] = Image.new(request_state.locals[:_body])
end
end
class OutputOK
def realize(request_state)
@@ -200,27 +200,49 @@
handler_configuration.global = configuration
handler_configuration.http_method = node.name
handler_configuration.uri_matchers = node.values.map do |matcher|
case matcher
- when %r{^:[^/]+/.*/$}
- name, regexp = *matcher.match(%r{^:([^/]+)/(.*)/$}).captures
+ # URI component matchers
+ when %r{^:([^/]+)/(.*)/$} # :foobar/.*/
+ name = $1
+ regexp = $2
Matcher.new(name.to_sym) do
Regexp.new("(#{regexp})")
end
- when /^:.+\?$/
- name = matcher.sub(/^:(.+)\?$/, '\1').to_sym
+ when /^:(.+)\?(.*)$/ # :foo?bar
+ name = $1.to_sym
+ default = $2
Matcher.new(name) do
- ->{match(name) || captures.push('')}
+ ->{match(name) || captures.push(default)}
end
- when /^:/
- name = matcher.sub(/^:/, '').to_sym
+ when /^:(.+)$/ # :foobar
+ name = $1.to_sym
Matcher.new(name) do
name
end
- else
+ # Query string matchers
+ when /^\&([^=]+)=(.+)$/# ?foo=bar
+ name = $1
+ value = $2
Matcher.new(nil) do
- matcher
+ ->{req[name] && req[name] == value}
+ end
+ when /^\&:(.+)\?(.*)$/# &:foo?bar
+ name = $1
+ default = $2
+ Matcher.new(name.to_sym) do
+ ->{captures.push(req[name] || default)}
+ end
+ when /^\&:(.+)$/# &:foo
+ name = $1
+ Matcher.new(name.to_sym) do
+ ->{req[name] && captures.push(req[name])}
+ end
+ # String URI component matcher
+ else # foobar
+ Matcher.new(nil) do
+ Regexp.escape(matcher)
end
end
end
handler_configuration.image_sources = []
handler_configuration.stores = []