Class: Visor::Image::GetImage
- Inherits:
-
Goliath::API
- Object
- Goliath::API
- Visor::Image::GetImage
- Includes:
- Common::Exception, Common::Util
- Defined in:
- lib/image/routes/get_image.rb
Overview
Get image data and metadata for the given id.
Instance Method Summary collapse
-
#exit_error(code, message) ⇒ Array
Produce an HTTP response with an error code and message.
-
#on_close(env) ⇒ Object
On connection close log a message.
-
#on_headers(env, headers) ⇒ Object
Pre-process headers as they arrive and load them into a environment variable.
-
#response(env) ⇒ Object
Query database to retrieve the wanted image meta and return it in headers, along with the image file, if any, streaming it in request body.
Instance Method Details
#exit_error(code, message) ⇒ Array
Produce an HTTP response with an error code and message.
73 74 75 76 |
# File 'lib/image/routes/get_image.rb', line 73 def exit_error(code, ) logger.error [code, {}, {code: code, message: }] end |
#on_close(env) ⇒ Object
On connection close log a message.
62 63 64 |
# File 'lib/image/routes/get_image.rb', line 62 def on_close(env) logger.info 'Connection closed' end |
#on_headers(env, headers) ⇒ Object
Pre-process headers as they arrive and load them into a environment variable.
18 19 20 21 |
# File 'lib/image/routes/get_image.rb', line 18 def on_headers(env, headers) logger.debug "Received headers: #{headers.inspect}" env['headers'] = headers end |
#response(env) ⇒ Object
Query database to retrieve the wanted image meta and return it in headers, along with the image file, if any, streaming it in request body.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/image/routes/get_image.rb', line 28 def response(env) begin (env, vas) = vms.get_image(params[:id]) uri = [:location] if uri store = Visor::Image::Store.get_backend(uri, configs) store.file_exists? end rescue Forbidden => e return exit_error(403, e.) rescue NotFound => e return exit_error(404, e.) rescue InternalError => e exit_error(503, e.) end custom = {'Content-Type' => 'application/octet-stream', 'X-Stream' => 'Goliath'} headers = (, custom) if uri EM.next_tick do store.get { |chunk| chunk ? env.chunked_stream_send(chunk) : env.chunked_stream_close } end chunked_streaming_response(200, headers) else [200, headers, nil] end end |