327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
# File 'lib/httpimagestore/configuration/handler.rb', line 327
def self.parse(configuration, node)
handler_configuration =
Struct.new(
:global,
:http_method,
:uri_matchers,
:sources,
:processors,
:stores,
:output
).new
handler_configuration.global = configuration
handler_configuration.http_method = node.name
handler_configuration.uri_matchers = node.values.map do |matcher|
case matcher
when %r{^:([^/]+)/(.*)/$} name = $1.to_sym
_regexp = Regexp.new($2)
regexp = Regexp.new("(#{$2})")
Matcher.new([name], 'Regexp', _regexp) do
regexp
end
when %r{^/(.*)/$} regexp = $1
_regexp = Regexp.new($1)
names = Regexp.new($1).names.map{|n| n.to_sym}
Matcher.new(names, 'Regexp', _regexp) do
-> {
matchdata = env["PATH_INFO"].match(/\A\/(?<_match_>#{regexp})(?<_tail_>(?:\/|\z))/)
next false unless matchdata
path, *vars = matchdata.captures
env["SCRIPT_NAME"] += "/#{path}"
env["PATH_INFO"] = "#{vars.pop}#{matchdata.post_match}"
captures.push(*vars)
}
end
when /^:(.+)\?(.*)$/ name = $1.to_sym
default = $2
Matcher.new([name], 'SegmentDefault', "<segment>|#{default}") do
->{match(name) || captures.push(default)}
end
when /^:(.+)$/ name = $1.to_sym
Matcher.new([name], 'Segment', '<segment>') do
name
end
when /^\&([^=]+)=(.+)$/ name = $1.to_sym
value = $2
Matcher.new([name], 'QueryKeyValue', "#{name}=#{value}") do
->{req.GET[name.to_s] && req.GET[name.to_s] == value && captures.push(req.GET[name.to_s])}
end
when /^\&:(.+)\?(.*)$/ name = $1.to_sym
default = $2
Matcher.new([name], 'QueryKeyDefault', "#{name}=<key>|#{default}") do
->{captures.push(req.GET[name.to_s] || default)}
end
when /^\&:(.+)$/ name = $1.to_sym
Matcher.new([name], 'QueryKey', "#{name}=<key>") do
->{req.GET[name.to_s] && captures.push(req.GET[name.to_s])}
end
else Matcher.new([], "Literal", matcher) do
Regexp.escape(matcher)
end
end
end
handler_configuration.sources = []
handler_configuration.processors = []
handler_configuration.stores = []
handler_configuration.output = nil
node.grab_attributes
if handler_configuration.http_method != 'get'
handler_configuration.sources << InputSource.new
end
configuration.handlers << handler_configuration
self.new(handler_configuration).parse(node)
handler_configuration.output = OutputOK.new unless handler_configuration.output
end
|