HttpContentType
This gem allows you to check the Content-Type of any asset accessible via HTTP.
Compatible with Ruby >= 1.9, JRuby (1.9 mode) or Rubinius (1.9 mode).
Installation
Add this line to your application's Gemfile:
gem 'http_content_type'
And then execute:
$ bundle
Or install it yourself as:
$ gem install http_content_type
Usage
checker = HttpContentType::Checker.new('http://domain.com/video.mp4')
checker.error? # => false (true if there was an error requesting
# the asset)
checker.found? # => true (the asset was found, i.e. request
# returned an `Net::HTTPSuccess` response)
checker.expected_content_type # => 'video/mp4' (the expected content type is
# based on file extension but can also be
# hardcoded with the :expected_content_type option)
checker.content_type # => 'video/mp4'
checker.valid_content_type? # => true
Options
:timeout
checker = HttpContentType::Checker.new('http://domain.com/video.mp4', timeout: 10) # in seconds
:expected_content_type
checker = HttpContentType::Checker.new('http://domain.com/dynamic_asset.php', expected_content_type: 'video/mp4')
checker.expected_content_type # => 'video/mp4'
checker.content_type # => 'video/mp4'
checker.valid_content_type? # => true
Development
Pull requests are very welcome! Please try to follow these simple rules if applicable:
- Please create a topic branch for every separate change you make.
- Make sure your patches are well tested. All specs must pass on Travis CI.
- Update the Yard documentation.
- Update the README.
- Update the CHANGELOG for noteworthy changes (don't forget to run
bundle exec pimpmychangelog
and watch the magic happen)! - Please do not change the version number.
Author
Contributors
https://github.com/jilion/http_content_type/graphs/contributors