133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/httpimagestore/configuration/handler.rb', line 133
def self.parse(configuration, node)
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', "#{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', "<key>|#{default}") do
->{captures.push(req.GET[name.to_s] || default)}
end
when /^\&:(.+)$/ name = $1.to_sym
Matcher.new([name], 'QueryKey', "<key>") do
->{req.GET[name.to_s] && captures.push(req.GET[name.to_s])}
end
else Matcher.new([], matcher, nil) do
Regexp.escape(matcher)
end
end
end
handler_configuration = HandlerConfiguration.new(configuration, node.name, uri_matchers)
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
|