Method: Middleware::ContentTypeValidator#call

Defined in:
lib/chef-licensing/restful_client/middleware/content_type_validator.rb

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/chef-licensing/restful_client/middleware/content_type_validator.rb', line 6

def call(env)
  @app.call(env).on_complete do |response_env|
    content_type = response_env[:response_headers]["content-type"]
    body = response_env[:body]
    # trim the body to 1000 characters to avoid printing a huge string in the error message
    body = body[0..1000] if body.is_a?(String)
    raise ChefLicensing::UnsupportedContentType, error_message(content_type, body) unless content_type == "application/json"
  end
end