Class: Configuration::OutputImage
- Inherits:
-
HandlerStatement
show all
- Includes:
- ClassLogging, ImageName, LocalConfiguration, PerfStats
- Defined in:
- lib/httpimagestore/configuration/output.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Scope
node_parsers, #parse, register_node_parser
Constructor Details
#initialize(name, cache_control) ⇒ OutputImage
Returns a new instance of OutputImage.
107
108
109
110
111
|
# File 'lib/httpimagestore/configuration/output.rb', line 107
def initialize(name, cache_control)
@name = name
@cache_control = cache_control
with_image_name(name)
end
|
Class Method Details
.match(node) ⇒ Object
96
97
98
|
# File 'lib/httpimagestore/configuration/output.rb', line 96
def self.match(node)
node.name == 'output_image'
end
|
.parse(configuration, node) ⇒ Object
100
101
102
103
104
105
|
# File 'lib/httpimagestore/configuration/output.rb', line 100
def self.parse(configuration, node)
configuration.output and raise StatementCollisionError.new(node, 'output')
image_name = node.grab_values('image name').first
cache_control = node.grab_attributes('cache-control').first
configuration.output = self.new(image_name, cache_control)
end
|
Instance Method Details
#realize(request_state) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/httpimagestore/configuration/output.rb', line 113
def realize(request_state)
image = request_state.images[@name]
mime_type =
if image.mime_type
image.mime_type
else
log.warn "image '#{@name}' has no mime type; sending 'application/octet-stream' content type"
'application/octet-stream'
end
cache_control = @cache_control
_context = self
request_state.output do
_context.measure "sending response image data", "mime type: #{mime_type} (image #{image.data.bytesize} bytes)" do
res['Cache-Control'] = cache_control if cache_control
write 200, mime_type, image.data
end
end
end
|