Class: Scales::Server::ContentType

Inherits:
Object
  • Object
show all
Includes:
Goliath::Rack::AsyncMiddleware
Defined in:
lib/scales-server/content_type.rb

Constant Summary collapse

TYPES =
Scales::Helper::ContentTypes::TYPES

Instance Method Summary collapse

Constructor Details

#initialize(app, format = 'html') ⇒ ContentType

Returns a new instance of ContentType.



9
10
11
# File 'lib/scales-server/content_type.rb', line 9

def initialize(app, format = 'html')
  @app, @format = app, format
end

Instance Method Details

#parse_from_format?(uri) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/scales-server/content_type.rb', line 18

def parse_from_format?(uri)
  content_type = TYPES[@format.to_sym]
  TYPES.each { |format, type| content_type = type and break if uri =~ /\.#{format}(\?|$)/ }
  content_type
end

#post_process(env, status, headers, body) ⇒ Object



13
14
15
16
# File 'lib/scales-server/content_type.rb', line 13

def post_process(env, status, headers, body)
  headers['Content-Type'] = parse_from_format?(env['REQUEST_URI'])
  [status, headers, body]
end